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

Remove redundant lookup funcs in fixup.py #11253

Merged
merged 7 commits into from
Oct 8, 2021

Conversation

97littleleaf11
Copy link
Collaborator

@97littleleaf11 97littleleaf11 commented Oct 3, 2021

Description

Removes the redundant lookup funcs in fixup.py. Related to #4157.

  • Removes lookup_qualified_stnode: uncessary nested call to lookup_fully_qualified
  • Removes lookup_qualified: inconsistency return types with other lookup_qualified funcs. Let the callers extract the SymbolNode from the SymbolTableNode.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! We need to be careful with these changes, since there are various subtle differences that could cause (rare) breakage. On the other hand, cleaning these up will make it less likely that things will break in the future.

mypy/fixup.py Outdated Show resolved Hide resolved
mypy/lookup.py Outdated
@@ -10,7 +10,7 @@


def lookup_fully_qualified(name: str, modules: Dict[str, MypyFile],
raise_on_missing: bool = False) -> Optional[SymbolTableNode]:
suppress_errors: bool = False) -> Optional[SymbolTableNode]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Negating the meaning of a bool argument can be dangerous, since it will silently change behavior in all call sites that haven't been updated.

I think it's better to leave this unchanged. Instead, you could change mypy/fixup.py to use raise_on_missing instead of suppress_errors for consistency. Changing fixup seems better since it's more of an internal thing.

mypy/fixup.py Outdated Show resolved Hide resolved
mypy/fixup.py Outdated
@@ -312,8 +298,7 @@ def missing_info(modules: Dict[str, MypyFile]) -> TypeInfo:
dummy_def.fullname = suggestion

info = TypeInfo(SymbolTable(), dummy_def, "<missing>")
obj_type = lookup_qualified(modules, 'builtins.object', False)
assert isinstance(obj_type, TypeInfo)
obj_type = lookup_qualified_typeinfo(modules, 'builtins.object', False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For bool arguments it will be clearer to use a keyword argument instead of positional.

@@ -87,7 +87,7 @@ def argument(self, ctx: 'mypy.plugin.ClassDefContext') -> Argument:
if self.converter.name:
# When a converter is set the init_type is overridden by the first argument
# of the converter method.
converter = lookup_qualified_stnode(ctx.api.modules, self.converter.name, True)
converter = lookup_fully_qualified(self.converter.name, ctx.api.modules, True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, it's awkward that this imported a lookup function from mypy.fixup.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks for the updates! Left a bunch of comments about adding more keyword args to make it explicit whether we are using raise_on_missing or allow_missing.

mypy/fixup.py Outdated Show resolved Hide resolved
mypy/fixup.py Outdated Show resolved Hide resolved
mypy/fixup.py Outdated Show resolved Hide resolved
mypy/fixup.py Outdated Show resolved Hide resolved
mypy/fixup.py Outdated Show resolved Hide resolved
mypy/fixup.py Outdated Show resolved Hide resolved
mypy/fixup.py Outdated Show resolved Hide resolved
mypy/fixup.py Show resolved Hide resolved
mypy/fixup.py Show resolved Hide resolved
@97littleleaf11
Copy link
Collaborator Author

Thanks for reviewing! Making allow_missing and raise_on_missing keyword-only args is quite helpful since they're confusing when calling.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks!

@JukkaL JukkaL merged commit 15f2385 into python:master Oct 8, 2021
@97littleleaf11 97littleleaf11 deleted the move-lookup branch October 14, 2021 16:11
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.

2 participants