You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of python 3.8, the Literal type hint exists by default. It is extremely useful, but cannot be used in geoutils directly as it is not supported by python 3.7! Luckily, there's a solution...
Why it's important
If I have a function that returns a different type depending on a boolean flag, types should be annotated accordingly:
The problem without py38+ is that the type will be int | str no matter what flag is given.
This will always return an int if flag==True and str if not. The solution is overload and Literal:
fromtypingimportoverload, Literal@overloaddeffunc(flag: Literal[True]) ->int: ...
@overloaddeffunc(flag: Literal[False]) ->str: ...
# here goes the function definition
The solution
typing-extensions , the official backport of new typing functions!
Using conditionals in the pip and conda requirements, we can make sure that it is only installed for python <=3.7.
This has already been a big problem in #208 and #216 , so this should be fixed soon!
The text was updated successfully, but these errors were encountered:
As of python 3.8, the
Literal
type hint exists by default. It is extremely useful, but cannot be used in geoutils directly as it is not supported by python 3.7! Luckily, there's a solution...Why it's important
If I have a function that returns a different type depending on a boolean flag, types should be annotated accordingly:
The problem without py38+ is that the type will be
int | str
no matter what flag is given.This will always return an
int
ifflag==True
andstr
if not. The solution isoverload
andLiteral
:The solution
typing-extensions , the official backport of new typing functions!
Using conditionals in the pip and conda requirements, we can make sure that it is only installed for python <=3.7.
This has already been a big problem in #208 and #216 , so this should be fixed soon!
The text was updated successfully, but these errors were encountered: