Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Created March 29, 2021 10:46
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/649f7a787fad9660b2202a541e4ad3a9 to your computer and use it in GitHub Desktop.
Save MartinThoma/649f7a787fad9660b2202a541e4ad3a9 to your computer and use it in GitHub Desktop.
from typing import Union
def upcase(s: Union[str, bytes]) -> Union[str, bytes]:
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