Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Created March 29, 2021 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinThoma/cc39760e928ec7dd917406e984e9a1a9 to your computer and use it in GitHub Desktop.
Save MartinThoma/cc39760e928ec7dd917406e984e9a1a9 to your computer and use it in GitHub Desktop.
from typing import overload
@overload
def upcase(s: str) -> str:
...
@overload
def upcase(s: bytes) -> bytes:
...
def upcase(s):
if isinstance(s, str):
return s.upper()
elif isinstance(s, bytes):
return bytes(x - 0x20 if 0x61 <= x <= 0x7A else x for x in s)
else:
raise TypeError("need str or bytes")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment