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
Treat any instance of a Mapping
as a Dict
.
#45
Conversation
Without this we're winding up with a bunch types like: ``` Union[Dict[str, str], OrderedDict] ``` On functions that can accept any `Mapping`. I was woried about covariance/contravariance with this and `mypy` seems to be OK with that: ```python from collections import OrderedDict from typing import Dict def foo(a: Dict[str, str]) -> Dict[str, str]: return OrderedDict([('a', 'a'), ('b', 'b')]) foo(OrderedDict([('a', 'a'), ('b', 'b')])) ```
Can you change this translation to the second pass (i.e. pyannotate_tools/annotations)? The |
@gvanrossum Thanks for the feedback! Instead of using |
I'm still not happy with doing any kind of unification of this kind during runtime collection. There are important API differences between Dict and OrderedDict and I don't want those to be lost in type_info.json. You haven't explained to me why you can't do this in the second pass. |
@gvanrossum The reason this is happening in the first pass is if we do this in the second pass we don't collect any information on key/value types. We can add a |
Oh! But I would like to still keep the actual type (dict, collections.defaultdict or collections.OrderedDict) in type_info.json. If you can do that I think this is a great improvement! |
Do you think you will have time for this soon? I am waiting to release version 1.0.3. |
@gvanrossum Working on it now! |
@rowillia Are you still interested in pursuing this? I need to decide whether to release PyAnnotate 1.0.3 with or without it. It will likely be the last release this year due to my vacation schedule and I'd like to release it today or Monday 12/11 at the latest. |
Without this we're winding up with a bunch types like:
On functions that can accept any
Mapping
.I was woried about covariance/contravariance with this and
mypy
seems to be OK with that: