-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Use OrderedDict for raw per-module options to preserve section order #3678
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
Conversation
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.
Looks good -- just one small comment.
mypy/options.py
Outdated
|
||
# Per-module options (raw) | ||
self.per_module_options = {} # type: Dict[Pattern[str], Dict[str, object]] | ||
self.per_module_options = collections.OrderedDict() # type: MutableMapping[Pattern[str], Dict[str, object]] |
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.
What's the reason to use MutableMapping
?
Dict
should still work, right?
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 think we should consider making this of type OrderedDict
, because that's important for the semantics.
Yes, Dict still works, but the call sites don't need it -- MutableMapping
is sufficient. Or maybe we should specify OrderedDict in the annotation
too? (Note that for the value type we have to use exactly Dict because of
invariance.)
|
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.
This LGTM, with one slight nit. Feel free to merge after fixing the nit. If you disagree with the nit, go ahead and merge too -- I don't feel particularly strongly about it.
mypy/options.py
Outdated
|
||
# Per-module options (raw) | ||
self.per_module_options = {} # type: Dict[Pattern[str], Dict[str, object]] | ||
self.per_module_options = collections.OrderedDict() # type: MutableMapping[Pattern[str], Dict[str, object]] |
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 think we should consider making this of type OrderedDict
, because that's important for the semantics.
Agreed, pushed a fix. Will merge myself once tests pass. |
Fixes #3675.
Note that the problem only occurs on Python 3.5 and earlier, since in Python 3.6 the standard
dict
type preserves order. Also note that this relies onConfigParser
preserving order -- which it does (it usesOrderedDict
for everything by default).