Skip to content

Report NewType used as the first argument of issubclass() - #22505

Closed
zhengdaodeguL wants to merge 1 commit into
python:masterfrom
zhengdaodeguL:fix/issubclass-newtype-22504
Closed

zhengdaodeguL wants to merge 1 commit into
python:masterfrom
zhengdaodeguL:fix/issubclass-newtype-22504

Conversation

@zhengdaodeguL

Copy link
Copy Markdown

Fixes #22504

issubclass() with a NewType as its first argument fails at runtime (TypeError: issubclass() arg 1 must be a class), but mypy only reported a NewType used as the second argument. Now the first argument is checked too, using the existing flatten() expansion so a NewType inside a tuple is also caught. isinstance()'s first argument is intentionally untouched (it takes an instance value, and a NewType value is its base-class value at runtime).

Added issubclass(T, object) and issubclass((T,), object) expectations to testNewTypeWithIsInstanceAndIsSubclass in check-newtype.test.

issubclass() with a NewType as its first argument fails at runtime
(TypeError: issubclass() arg 1 must be a class), but mypy only
reported a NewType used as the second argument. Check the first
argument the same way, including NewTypes inside a tuple.

Fixes python#22504
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

issubclass() with a NewType as the first argument is not reported

2 participants