Closed hynek closed 6 years ago
So um @ethanhs does this look overall sensible to you?
I mean it will work here, and seems to make sense. You aren't doing anything too complicated.
Is this an approach we could take on attrs?
Probably not, as you need some runtime typing things Generic
, overload
, etc. in attrs.
What about the TYPE_CHECKING
thingie I’ve seen thrown around? I know that there’s one in the typing
module but I saw people saying that even if I go the X=False; if X:
it has to be called the same way?
TYPE_CHECKING
might help here, but as I said in the attrs PR, you will likely end up duplicating things (eg overload, Generic) in the else branch.
Wait what do you mean by “duplicating things”? I’m just talking about how to literally write down the currently if False:
branch and if it makes semantically any sense to introduce an TYPE_CHECKING variable (instead of bare False or your suggested MYPY).
It is more idiomatic to use MYPY
, TYPE_CHECKING
was added to typing
to avoid import cycles and such. Mypy itself uses if MYPY:
to work around some missing features in 3.5.1. But it is up to personal preference in the end.
So here is an example:
MYPY=False
if MYPY:
from typing import Generic
else:
# define a class that pretends to be Generic
class A(Generic):
pass
Also I'm not sure I understand what you mean by
I saw people saying that even if I go the X=False; if X: it has to be called the same way?
What is "it" here and what do you mean by it being called?
So um @ethanhs does this look overall sensible to you? I consider it a finger exercise before moving to more complex projects including attrs.
Also ping @ambv for good measure.
Is this an approach we could take on
attrs
? One thing I’ve noticed is that we definitely losecast()
.