Skip to content

test_typing has strange assertIsInstance calls #111126

@sobolevn

Description

@sobolevn

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

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtopic-typingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions