Skip to content

Conversation

@AlexWaygood
Copy link
Member

Refs #7928

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

source: SoupStrainer
def __init__(self, source: SoupStrainer, result: Iterable[_PageElementT] = ...) -> None: ...
@overload
def __init__(self, source: SoupStrainer) -> None: ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I haven't following this so far, but shouldn't this annotate self to bind _PageElementT?

Copy link
Member Author

@AlexWaygood AlexWaygood Jun 16, 2022

Choose a reason for hiding this comment

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

This is basically the same approach that we've had for a while for some generic collections in builtins and collections, e.g. this has been the first overload for builtins.list for (at least) two years now:

class list(MutableSequence[_T], Generic[_T]):
@overload
def __init__(self) -> None: ...

If the constructor-method overload picked is one where there are no TypeVars present at all, despite the class being generic, the type checker will require the user to provide an explicit type annotation, the same as happens if you try to initialise an empty list 🙂

https://mypy-play.net/?mypy=latest&python=3.10&gist=dcbf1006ff7606d02d5670171bc6cae1

@srittau srittau merged commit a2ef476 into master Jun 16, 2022
@srittau srittau deleted the sqlalchemy branch June 16, 2022 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants