basedmypy
basedmypy copied to clipboard
Bare literal types (without `Literal`) and support `ForwardRef` in types tracking issue
# from __future__ import annotations
from typing import ForwardRef
def foo(a: "asdf") -> True: # literal string `"asdf"`
...
MyType: TypeAlias = int | ForwardRef("asdf") # a forward reference to the type `asdf`
- [x] support non string literal types (#137)
- [x] int
- [x] bool
- [x] Enum
- [ ] tuple
- [ ] support strings as literal types in type annotations (#361)
- [ ] support
ForwardRefor some alternative in type aliases
An easy route would be to not use ForwardRef at all and just force usage of Literal in type aliases.
What about dict and Protocol literals?
a: {'a': int, 'b': str} = {'a': 1, str}
def (a: Protocol[{'a': int, 'b': str}]): ...