Skip to content

gh-131936: Relax assertion in _Py_CalculateSuggestions #131943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Mar 31, 2025

Another option is to validate that _generate_suggestions is given exactly a list, but I don't see why we should require that. I'm not adding a blurb entry because _generate_suggestions is solely internal.


# gh-131936: _Py_CalculateSuggestions wanted exactly a list
class MyList(list):
def __getitem__(self, *_):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just:

Suggested change
def __getitem__(self, *_):
def __getitem__(self, item):

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks wrong. MyList.__getitem__() should be called, but it's not.

Either require the exact list type, or modify the code to use PySequence_GetItem(). I prefer to keep the exact list type. It's an internal module, it doesn't have to support list subclasses.

@ZeroIntensity
Copy link
Member Author

I put up #131945 as an alternative. I'm not sure what the rule/expected behavior is for PyList APIs and subclasses, so I'll leave this open for now.

@vstinner
Copy link
Member

I merged #131945 instead.

@vstinner vstinner closed this Mar 31, 2025
@ZeroIntensity ZeroIntensity deleted the gh-131936-suggestions-crash branch March 31, 2025 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants