-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
TypedDict handles unicode names and keys inconsistently in Python 2 #6123
Comments
Hmm, it also seems like the keys are also handled inconsistently at well. Mypy and the Python runtime both let you have unicode keys. They also both accept However, mypy will report an error when doing |
Why isn’t this a typeshed issue? |
@gvanrossum -- I wasn't sure what the correct fix for the first The issue in the second comment (the inconsistency between Basically, mypy special-cases both methods and hard-codes in the assumption that |
I think that unicode literals should be accepted everywhere, since using |
Closing due to Python 2 feature freeze (#12237). |
I noticed an minor inconsistency in the way mypy handles the following program in Python 2:
Mypy type-checks this problem without errors. However, if you actually try running this program at runtime, you get the following exception:
You have to do
MyDict = TypedDict(b'MyDict', {'foo': int})
to get this program to both typecheck and run.I'm not sure whether the correct thing to do is modify mypy to report an error or to relax the runtime implementation.
On one hand,
type(name, bases, dict)
legitimately won't accept unicode names in Python 2 so perhaps we should add a check to mypy. On the other, we don't get the same kind of runtime error when creatingNamedTuples
, so perhaps it's better to try and convert the unicode name to str insideTypedDict
for consistency.The text was updated successfully, but these errors were encountered: