Skip to content

Add typing.OrderedDict to type_aliases #9389

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

Merged
merged 3 commits into from
Oct 19, 2020
Merged

Add typing.OrderedDict to type_aliases #9389

merged 3 commits into from
Oct 19, 2020

Conversation

septatrix
Copy link
Contributor

Description

In 3.7.2 typing.OrderedDict was added to the typing module. Beforehand the correct way to annotate an OrderedDict was as a string or using the __future__ import. However since it has been added to the stdlib it has not been added to the type_aliases for mypy as it should have.

Sample File

from typing import OrderedDict

# substituting with collections.OrderedDict soothes mypy but fails at runtime
d: OrderedDict[str, int] = OrderedDict()
$ mypy test.py
test.py:3: error: Variable "typing.OrderedDict" is not valid as a type
test.py:3: note: See https://mypy.readthedocs.io/en/latest/common_issues.html#variables-vs-type-aliases
test.py:3: error: "_Alias" not callable
Found 2 errors in 1 file (checked 1 source file)

Test Plan

I do not know if the other aliases are tested anywhere. If so it might be a good idea to add a test there...

@septatrix
Copy link
Contributor Author

Sadly I do not know why the windows CI fails however it seems to be the same on master?

The travis CI fails for mypyc with the same errors as I listed above for the mypy version before this patch. Does it contain a different database for valid type aliases?

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 4, 2020

Maybe the problem is that typing.OrderedDict is only defined on Python 3.7 and later: https://github.com/python/typeshed/blob/master/stdlib/3/typing.pyi#L97

The CI may have been fixed. Can you rebase and see if it still happens?

@septatrix
Copy link
Contributor Author

Maybe the problem is that typing.OrderedDict is only defined on Python 3.7 and later: https://github.com/python/typeshed/blob/master/stdlib/3/typing.pyi#L97

However the test for Python 3.6 passes. Also 3.7 with mypyc fails. This would only explain the failure for the 3.5 test with mypyc.

The CI may have been fixed. Can you rebase and see if it still happens?

Rebasing fixed the windows CI errors.

@septatrix
Copy link
Contributor Author

@ilevkivskyi is there maybe another place where this mapping gets stored?

@septatrix
Copy link
Contributor Author

This is a rather annoying flaw in mypy for us as this forces us to use type comments in many places which we want to avoid as they do not work together well with formatters and other tools. The root problem has been found but sadly mypyc behaves different from mypy for some reason. I have been tinkering around a bit but have not been able to find the cause of this in the last few days. If anyone has another idea where this could come from I would be pleased to get some help as I do not know what else to try. Maybe I missed an important part for version detection or similar in the ordered_dict.py file or similar...

@msullivan
Copy link
Collaborator

Yeah mypyc is obnoxiously fiddly about conditional compilation stuff. That part of the code seems to be a distraction, though; there's no real need to change anything about how mypy uses OrderedDict. The bigger problem here is that the change doesn't actually fix the problem, unfortunately. Something weirder is going on with these aliases.

@msullivan msullivan closed this Oct 19, 2020
@msullivan msullivan reopened this Oct 19, 2020
@msullivan
Copy link
Collaborator

Alright I applied some brute force to fix this issue, which is annoying. There should be a better way to fix it.

@msullivan msullivan merged commit 6bbc8c5 into python:master Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy