Skip to content
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

test_typing has strange assertIsInstance calls #111126

Closed
sobolevn opened this issue Oct 20, 2023 · 0 comments
Closed

test_typing has strange assertIsInstance calls #111126

sobolevn opened this issue Oct 20, 2023 · 0 comments
Assignees
Labels
tests Tests in the Lib/test dir topic-typing type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Oct 20, 2023

Bug report

These line are problematic:

with self.assertRaises(TypeError):
self.assertIsInstance(f, Callable[[], None])
with self.assertRaises(TypeError):
self.assertIsInstance(f, Callable[[], Any])
with self.assertRaises(TypeError):
self.assertNotIsInstance(None, Callable[[], None])
with self.assertRaises(TypeError):
self.assertNotIsInstance(None, Callable[[], Any])

Why?

  1. self.assertIsInstance gives the intention that this will return True
  2. self.assertNotIsInstance gives the intention that this will return False
  3. Technically self.assert[Not]IsInstance can raise TypeError on its own (but not in practice)

However, this will always fail with TypeError.
I propose to use just isintance instead.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir topic-typing labels Oct 20, 2023
@sobolevn sobolevn self-assigned this Oct 20, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 20, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 20, 2023
…in `test_typing` (pythonGH-111127)

(cherry picked from commit ea7c26e)

Co-authored-by: Nikita Sobolev <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 20, 2023
…in `test_typing` (pythonGH-111127)

(cherry picked from commit ea7c26e)

Co-authored-by: Nikita Sobolev <[email protected]>
AlexWaygood pushed a commit that referenced this issue Oct 20, 2023
… in `test_typing` (GH-111127) (#111130)

gh-111126: Use `isinstance` instead of `assert[Not]IsInstance` in `test_typing` (GH-111127)
(cherry picked from commit ea7c26e)

Co-authored-by: Nikita Sobolev <[email protected]>
AlexWaygood pushed a commit that referenced this issue Oct 20, 2023
… in `test_typing` (GH-111127) (#111131)

gh-111126: Use `isinstance` instead of `assert[Not]IsInstance` in `test_typing` (GH-111127)
(cherry picked from commit ea7c26e)

Co-authored-by: Nikita Sobolev <[email protected]>
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants