Skip to content

bpo-46611: add coverage to instance and class checks in typing.py #31078

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 3 commits into from
Feb 7, 2022

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Feb 2, 2022

Some proofs that these lines were not covered:
Снимок экрана 2022-02-02 в 16 38 20
Снимок экрана 2022-02-02 в 16 12 59

Now, they are! 👍

https://bugs.python.org/issue46611

self.assertIsInstance({}, x)
self.assertTrue(issubclass(dict, x))
def test_instancecheck_and_subclasscheck(self):
for x in [int | str, typing.Union[int, str]]:
Copy link
Member

Choose a reason for hiding this comment

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

Minor style thing;

Suggested change
for x in [int | str, typing.Union[int, str]]:
for x in (int | str, typing.Union[int, str]):

Tuple parentheses are interpreted as grouping things, compared to a specific list object (+ avoid runs of brackets)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! () and [] surely have a different meaning here. Thanks, I will change them tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I disagree with @merwok -- anything you iterate over surely is more like a list than like a tuple.

Copy link
Member

Choose a reason for hiding this comment

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

(But I also don't want to hold up the PR, so I'll merge regardless.)

@JelleZijlstra
Copy link
Member

@gvanrossum I think this one can be merged.

self.assertIsInstance({}, x)
self.assertTrue(issubclass(dict, x))
def test_instancecheck_and_subclasscheck(self):
for x in [int | str, typing.Union[int, str]]:
Copy link
Member

Choose a reason for hiding this comment

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

(But I also don't want to hold up the PR, so I'll merge regardless.)

@gvanrossum gvanrossum merged commit 067c03b into python:main Feb 7, 2022
@miss-islington
Copy link
Contributor

Thanks @sobolevn for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10.
🐍🍒⛏🤄1�7

@miss-islington
Copy link
Contributor

Sorry @sobolevn and @gvanrossum, I had trouble checking out the 3.10 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 067c03bf40d13393209f0138fa9c4d5980c4ff8a 3.10

sobolevn added a commit to sobolevn/cpython that referenced this pull request Feb 7, 2022
…g.py` (pythonGH-31078)

(cherry picked from commit 067c03b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-bot
Copy link

GH-31182 is a backport of this pull request to the 3.10 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Feb 7, 2022
serhiy-storchaka pushed a commit that referenced this pull request Feb 7, 2022
…g.py` (GH-31078) (GH-31182)

(cherry picked from commit 067c03b)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants