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

Plugin api named_type() is ambiguous and inconsistent and broken #6578

Open
gvanrossum opened this issue Mar 20, 2019 · 3 comments
Open

Plugin api named_type() is ambiguous and inconsistent and broken #6578

gvanrossum opened this issue Mar 20, 2019 · 3 comments
Labels
priority-1-normal refactoring Changing mypy's internals topic-plugins The plugin API and ideas for new plugins

Comments

@gvanrossum
Copy link
Member

The plugin API defines two different interfaces (TypeAnalyzerPluginInterface and SemanticAnalyzerPluginInterface) that each define a method named_type(). These look almost identical, but looks are deceptive.

First, the specified signatures differ subtly:

  • The second argument to SemanticAnalyzerPluginInterface.named_type() is optional, while for TypeAnalyzerPluginInterface.named_type() is is mandatory.
  • Also the first argument name differs (qualified_name vs. plain name).

Second, the implementations differ:

  • The semantic analyzer (in semanal.py) starts the lookup in the local namespace, then globals, then builtins.
  • The type checker (in checker.py) has two different strategies: if there's no dot in the name, it starts in globals, then builtins; but if there's a dot, it starts in the table of modules (i.e. the current scope doesn't enter into it).

Third, the type checker's named_type() implementation doesn't actually take a list of type arguments at all -- it's a method with only one argument, the name to look up. It always fills in all type parameters with Any. (It looks like the method we want here is named_generic_type().)

Fourth, apparently mypy's own type checking doesn't catch the discrepancy between the implemented spec (only a name) and the interface spec (name + args).

@ilevkivskyi ilevkivskyi added refactoring Changing mypy's internals priority-1-normal topic-plugins The plugin API and ideas for new plugins labels Apr 2, 2019
@ilevkivskyi
Copy link
Member

This is related to #4157. We are going to fix this after we are done with the main part of the refactoring (i.e. soon).

@ilevkivskyi
Copy link
Member

Fourth, apparently mypy's own type checking doesn't catch the discrepancy between the implemented spec (only a name) and the interface spec (name + args).

This is a separate problem I think. @Michael0x2a do we already have an issue for this?

JukkaL pushed a commit that referenced this issue Oct 15, 2021
Related to #6578

This PR replaces lookup_qualified with lookup_fully_qualified for SemanticAnalyzer.named_type. 
Now it's consistant with the implementation of checker.named_type. This change also allows 
calling named_type without dunders.
JukkaL pushed a commit that referenced this issue Nov 4, 2021
Related to #6578.

builtin_type could be totally replaced with named_type after #11332. 
Also renames other builtin_type for consistency since all of them are 
actually calling named_type.
@plankthom
Copy link

FYI: sqlmypy is hit by this api change: dropbox/sqlalchemy-stubs#232

tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
)

Related to python#6578

This PR replaces lookup_qualified with lookup_fully_qualified for SemanticAnalyzer.named_type. 
Now it's consistant with the implementation of checker.named_type. This change also allows 
calling named_type without dunders.
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
Related to python#6578.

builtin_type could be totally replaced with named_type after python#11332. 
Also renames other builtin_type for consistency since all of them are 
actually calling named_type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-1-normal refactoring Changing mypy's internals topic-plugins The plugin API and ideas for new plugins
Projects
None yet
Development

No branches or pull requests

3 participants