detect invalid `Literal[Foo.foo | Foo.bar]` → `Literal[Foo.foo, Foo.bar]`
Open
Nobody has claimed this yet.
feature
topic-runtime-semantics
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
import enum
from typing import Literal
class Foo(enum.IntEnum):
foo = 1
bar = 2
def foo(bar: Literal[Foo.foo | Foo.bar]) -> None:
pass
ty detect this as invalid-type-form:
$ ty check t.py
t.py:10:22: error[invalid-type-form] Type arguments for `Literal` must be `None`, a literal value (int, bool, str, or bytes), or an enum member
(https://github.com/astral-sh/ty/issues/876#issuecomment-3669957183)
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 t.py and running the shown type-check command, then trace how Literal arguments containing enum members and the | expression are validated. Done means the example is handled as Literal[Foo.foo, Foo.bar] rather than reported as invalid-type-form, with a regression test covering it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100