Union(Type) and TypeForm
Open
Nobody has claimed this yet.
bug
topic-runtime-semantics
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
My function should analyze types.
Both when --warn-unreachable is enabled, and when checking typing.Union, and when checking types.UnionType, an error occurs.
code:
from types import UnionType
from typing import Any, Union
from typing_extensions import TypeForm
def f(t: TypeForm[Any]) -> Any:
if isinstance(t, Union):
pass
def g(t: TypeForm[Any]) -> Any:
if isinstance(t, UnionType):
pass
errors:
main.py:8: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo" [arg-type]
main.py:14: error: Statement is unreachable [unreachable]
Found 2 errors in 1 file (checked 1 source file)
in runtime, the behavior of both isinstance is equivalent.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example in main.py with mypy, with and without --warn-unreachable, and inspect how typing.Union and types.UnionType are handled when the value is annotated with typing_extensions.TypeForm. Done means the equivalent isinstance checks no longer produce the reported incompatible-type or unreachable-statement errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100