Skip to content

Fix TypeVars in beautifulsoup and SQLAlchemy #8087

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

Merged
merged 2 commits into from
Jun 16, 2022
Merged

Fix TypeVars in beautifulsoup and SQLAlchemy #8087

merged 2 commits into from
Jun 16, 2022

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. 🤖🎉

@@ -351,4 +351,7 @@ class SoupStrainer:

class ResultSet(list[_PageElementT], Generic[_PageElementT]):
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.

2 participants