basedmypy
basedmypy copied to clipboard
support `str` literals without `Literal`
a: "asdf" | "fdsa" = "asdf"
https://github.com/KotlinIsland/basedmypy/pull/137#discussion_r927212154
#1
#137 is currently set to close #1 but it doesn't fully resolve it. should it be split into separate issues?
yeah
I wonder what the plan is for dealing with this:
>>> class A:
@staticmethod
def foo() -> A:
return A()
Traceback (most recent call last):
File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
exec(code, self.locals)
File "<pyshell#4>", line 1, in <module>
File "<pyshell#4>", line 3, in A
NameError: name 'A' is not defined
So, the solution is to put A in quotes:
>>> class A:
@staticmethod
def foo() -> "A": # Does this return the literal "A"? or an instance of A?
return A()
>>> A.foo()
<__main__.A object at 0x7f086e4e3490>
How do you tell apart the literal "A" from the A?
We were thinking something like:
class A:
a: ForwardRef["A"]