Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@overlay doesn't play nicely with None #601

Open
pyhedgehog opened this issue Oct 23, 2024 · 0 comments
Open

@overlay doesn't play nicely with None #601

pyhedgehog opened this issue Oct 23, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@pyhedgehog
Copy link

pyhedgehog commented Oct 23, 2024

@overload
def f1(o: NoneType) -> str:
    return 'None'
@overload
def f1(o: int) -> str:
    return type(o).__name__
@overload
def f1(o: str) -> str:
    return type(o).__name__
print(f1(''))
print(f1(0))
print(f1(None))

Will fail with optional is None. I've found workaround:

@overload
def f1(o: Optional[NoneType]=None) -> str:
    return 'None'
@overload
def f1(o: Optional[int]) -> str:
    if o is None: return f1()
    return type(o).__name__
@overload
def f1(o: Optional[str]) -> str:
    if o is None: return f1()
    return type(o).__name__
print(f1(''))
print(f1(0))
print(f1(None))
print(f1())

This works, but this is awful. Especially awful is need to add if o is None to every variant (calls lexically last variant).
Any hints?

@inumanag inumanag added the bug Something isn't working label Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants