KEMBAR78
Use OrderedDict for raw per-module options to preserve section order by gvanrossum · Pull Request #3678 · python/mypy · GitHub
Skip to content

Conversation

gvanrossum
Copy link
Member

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 on ConfigParser preserving order -- which it does (it uses OrderedDict for everything by default).

Copy link
Collaborator

@ilinum ilinum left a 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]]
Copy link
Collaborator

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?

Copy link
Collaborator

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.

@gvanrossum
Copy link
Member Author

gvanrossum commented Jul 7, 2017 via email

Copy link
Collaborator

@ddfisher ddfisher left a 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]]
Copy link
Collaborator

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.

@gvanrossum
Copy link
Member Author

Agreed, pushed a fix. Will merge myself once tests pass.

@gvanrossum gvanrossum merged commit e03f41d into python:master Jul 11, 2017
@gvanrossum gvanrossum deleted the section-ordering branch July 11, 2017 19:48
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