Created
March 29, 2021 10:44
-
-
Save MartinThoma/cc39760e928ec7dd917406e984e9a1a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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