-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix imports of OrderedDict from typing to collections #5481
Conversation
@@ -27,7 +28,7 @@ | |||
from allennlp.models import Model | |||
|
|||
|
|||
StateDictType = Union[Dict[str, torch.Tensor], OrderedDict[str, torch.Tensor]] | |||
StateDictType = Union[Dict[str, torch.Tensor], Mapping[str, torch.Tensor]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to change this to Mapping because with OrderedDict
from collections I got TypeError: 'type' object is not subscriptable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, have you tried quoting OrderedDict
? Like
StateDictType = Union[Dict[str, torch.Tensor], Mapping[str, torch.Tensor]] | |
StateDictType = Union[Dict[str, torch.Tensor], "OrderedDict[str, torch.Tensor]"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry - haven't got time to respond and test. @epwalsh are you going to take this over? Saw you self-assigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@epwalsh thanks for letting me know that, that's helpful.
But you still might want to consider doing this PR, since OrderedDict from typing is deprecated since Python 3.9 and this code will break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Well if you'd like to finish it up I'm happy to reopen it then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll finish it up in January. Pls reopen. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@epwalsh looks like your suggested approach did not pass lint.. any ideas? not familiar with types within quotes
@ethanjyx, are you working on this again? |
@dirkgr this slipped through - do you have time to continue it? |
No problem. It turns out I don't have permission to fix the merge conflicts. Should be easy to resolve though. |
ping @epwalsh |
You can run those checks locally:
It looks to me like there is just one import missing. |
@epwalsh can you kick the CI off? thanks |
Hi @ethanjyx, you'll need to fix the merge conflicts before CI can run |
Closing since this PR is stale and we don't officially support 3.6 anymore, anyway. |
Changes proposed in this pull request:
Remove any imports of OrderedDict from typing module.
OrderedDict is not included into typing until Python 3.7.2, at my company right now we are using Python 3.6.9 and this is causing issues for us.
Also OrderedDict from typing is deprecated later since Python 3.9. Reference: https://docs.python.org/3/library/typing.html#typing.OrderedDict.
So importing OrderedDict from typing is not a good idea, and we change that to import from collections here.
Before submitting
section of the
CONTRIBUTING
docs.Writing docstrings section of the
CONTRIBUTING
docs.After submitting
codecov/patch
reports high test coverage (at least 90%).You can find this under the "Actions" tab of the pull request once the other checks have finished.