Skip to content

Instantly share code, notes, and snippets.

@Kludex
Created October 18, 2022 14:29
Show Gist options
  • Save Kludex/df69ce8194e68958256bb180512de85a to your computer and use it in GitHub Desktop.
Save Kludex/df69ce8194e68958256bb180512de85a to your computer and use it in GitHub Desktop.
Mandatorily have a parameter, either a or b.
from __future__ import annotations
from typing import overload
@overload
def potato(a: int, b: None = None) -> int:
...
@overload
def potato(*, a: None = None, b: int) -> int:
...
def potato(a: int | None = None, b: int | None = None) -> int:
return a or b
potato(None) # type: ignore[call-overload]
potato(1)
potato(b=1)
potato() # type: ignore[call-overload]
@Kludex
Copy link
Author

Kludex commented Oct 18, 2022

This is wrong. How can I make it compliant with the description?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment