Skip to content
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

Add annotations for ModuleType #1525

Merged
merged 2 commits into from
Apr 22, 2022
Merged

Conversation

cdce8p
Copy link
Member

@cdce8p cdce8p commented Apr 22, 2022

Description

Replace collections.namedtuple with typing.NamedTuple. An issue here is that ModuleType previously implemented a custom __new__ method which modified one parameter name type vs module_type. This PR modifies the constructor parameter name (module_type). That way all existing ModuleSpec instances can still access the type attribute.

I've added a changelog entry since technically it's a breaking change. However, I don't think anyone should be impacted by it. ModuleType is (almost ?) exclusively used for internal code.

@cdce8p cdce8p added the Maintenance Discussion or action around maintaining astroid or the dev workflow label Apr 22, 2022
@cdce8p cdce8p added this to the 2.12.0 milestone Apr 22, 2022
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2210064454

  • 20 of 20 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.009%) to 91.575%

Totals Coverage Status
Change from base Build 2209158259: 0.009%
Covered Lines: 9119
Relevant Lines: 9958

💛 - Coveralls

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice cleanup, and also performance improvement because named tuple using exec are slow. I think we were using module_type instead of type because type is a builtin and pylint is raising a warning for this.


_ModuleSpec = collections.namedtuple(
"_ModuleSpec", "name type location " "origin submodule_search_locations"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a useless implicit string concatenation here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, could have been to indicate the optional parameter originally, but I'm not certain.

@cdce8p
Copy link
Member Author

cdce8p commented Apr 22, 2022

I think we were using module_type instead of type because type is a builtin and pylint is raising a warning for this.

Probably. Unfortunately, that's always a risk when dealing with the name type. In this case it should be fine though. We are already using it for attribute access anyway and the new constructor arguments aren't causing any issues either.

@cdce8p cdce8p merged commit 23cb69a into pylint-dev:main Apr 22, 2022
@cdce8p cdce8p deleted the type-ModuleType branch April 22, 2022 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining astroid or the dev workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants