Skip to content

Make sure type(None) is used instead of None for the type argument of isinstance. #344

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
Mar 19, 2025

Conversation

Sachaa-Thanasius
Copy link
Contributor

Using None, whether alone or in a tuple, as the second argument of isinstance(...) raises a TypeError at runtime. It's not a valid type.

Sachaa-Thanasius and others added 2 commits March 12, 2025 14:50
… isinstance.

Using None, whether alone or in a tuple, as the second argument raises a TypeError.
@jaraco
Copy link
Member

jaraco commented Mar 19, 2025

This regression was added in 19e9575 (#329) (cc @Avasam). In the future, we should be careful not to change the behavior when applying type annotations, maybe even do an AST diff to highlight behavior changes hidden in a haystack of annotations.

@jaraco jaraco merged commit fee62ca into pypa:main Mar 19, 2025
20 checks passed
@Sachaa-Thanasius Sachaa-Thanasius deleted the invalid-isinstance branch March 19, 2025 23:12
@Avasam
Copy link
Contributor

Avasam commented Mar 19, 2025

Thanks for catching the regression.

I'm not sure why that change was even done in my PR, it doesn't affect static typing in any way.

What I think happened is that I used VSCode's PyLance to autofill some -> None return type annotations, it likely autofilled with types.NoneType. Then I must've search&replaced types.NoneType to None and missed in self-review that I introduced that change.

Worst part is it's even caught by pyright/pylance >.<
image

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