Skip to content

PYI016 fix introduces a TypeError for Union[None, None] #19403

@dscorbett

Description

@dscorbett

Summary

When all the elements of a Union are None, the fix for duplicate-union-member (PYI016) introduces a TypeError. Example:

$ cat >pyi016.py <<'# EOF'
from typing import Union
isinstance(None, Union[None, None])
# EOF

$ ruff --isolated check pyi016.py --select PYI016 --fix
Found 1 error (1 fixed, 0 remaining).

$ cat pyi016.py
from typing import Union
isinstance(None, None)

$ python pyi016.py 2>&1 | tail -n 1
TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union

Version

ruff 0.12.3 (5bc81f2 2025-07-11)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violationshelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions