basedmypy icon indicating copy to clipboard operation
basedmypy copied to clipboard

Bare literal types (without `Literal`) and support `ForwardRef` in types tracking issue

Open KotlinIsland opened this issue 4 years ago • 1 comments

# 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 ForwardRef or 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.

KotlinIsland avatar Oct 21 '21 22:10 KotlinIsland

What about dict and Protocol literals?

a: {'a': int, 'b': str} = {'a': 1, str}
def (a: Protocol[{'a': int, 'b': str}]): ...

KotlinIsland avatar Jan 19 '22 10:01 KotlinIsland