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 builtins. from error messages #5072

Closed
JelleZijlstra opened this issue May 17, 2018 · 5 comments · Fixed by #11522
Closed

Remove builtins. from error messages #5072

JelleZijlstra opened this issue May 17, 2018 · 5 comments · Fixed by #11522

Comments

@JelleZijlstra
Copy link
Member

Our error messages would be a bit more concise if we removed the builtins. part from type output, and perhaps typing. too. This would make error messages match up more closely with runtime syntax.

For example, we currently output None as builtins.None, which is a syntax error at runtime. Just outputting None would be more clear.

@ilevkivskyi
Copy link
Member

I think they should be already removed from almost everywhere (if not, this is a bug). The only place that shows all names full is the error for overloads. I think this is the one we need to fix first.

@JelleZijlstra
Copy link
Member Author

reveal_type also outputs builtins..

@ilevkivskyi
Copy link
Member

Yes, but TBH I think overloads are still more important, reveal_type is kind of debugging tool so it is more expected to show some verbose output.

@JelleZijlstra
Copy link
Member Author

JelleZijlstra commented May 17, 2018

There's a couple of others:

unit/check-bound.test:x = None # type: G[str] # E: Type argument "builtins.str" of "G" must be a subtype of "__main__.A"
unit/check-bound.test:class D3(C[str]): pass # E: Type argument "builtins.str" of "C" must be a subtype of "__main__.A"
unit/check-classes.test:tmp/foo.pyi:5: error: Invalid signature "def (foo.C, Any, Any) -> builtins.int"
unit/check-classes.test:main:6: error: Invalid signature "def (__main__.C, builtins.str, builtins.str) -> __main__.C"
unit/check-classes.test:main:6: error: Invalid signature "def (__main__.C, builtins.str, builtins.str) -> __main__.C"
unit/check-classes.test:    def __setattr__(self, name: int, value: int) -> None: ...  # E: Invalid signature "def (__main__.C, builtins.int, builtins.int)"
unit/check-classes.test:NT = NewType('NT', N) # E: Argument 2 to NewType(...) must be subclassable (got TypedDict('__main__.N', {'x': builtins.int}))
unit/check-classes.test:main:4: error: t: builtins.str
unit/check-classes.test:main:4: error: y: builtins.float
unit/check-expressions.test:main:4: error: x: builtins.int
unit/check-expressions.test:main:4: error: y: builtins.int
unit/check-expressions.test:main:4: error: z: builtins.int
unit/check-functions.test:main:4: error: a: builtins.int
unit/check-functions.test:main:4: error: b: builtins.int
unit/check-functions.test:main:6: error: a: builtins.int
unit/check-functions.test:main:6: error: b: builtins.int
unit/check-functions.test:main:6: error: c: builtins.int
unit/check-functions.test:main:9: error: a: builtins.float
unit/check-modules.test:tmp/has_getattr.pyi:1: error: Invalid signature "def (builtins.int, builtins.str) -> builtins.str"
unit/check-namedtuple.test:yb: G[int] # E: Type argument "builtins.int" of "G" must be a subtype of "Tuple[builtins.int, fallback=__main__.M]"
unit/check-selftype.test:    def foo(self: T) -> T:   # E: The erased type of self 'builtins.str' is not a supertype of its class '__main__.A'
unit/check-selftype.test:    def cfoo(cls: Type[T]) -> T:  # E: The erased type of self 'Type[builtins.str]' is not a supertype of its class 'Type[__main__.A]'
unit/check-typeddict.test:yb: G[int] # E: Type argument "builtins.int" of "G" must be a subtype of "TypedDict('__main__.M', {'x': builtins.int})"
unit/check-unions.test:(e1, e2) = e  # E: 'builtins.int' object is not iterable
unit/check-unions.test:x, y = bad # E: 'builtins.int' object is not iterable \
unit/check-unions.test:           # E: 'builtins.str' object is not iterable

@ilevkivskyi
Copy link
Member

Oh wow, this would be quite some work to clean-up. Also this needs to switch to using double quotes probably "...".

ilevkivskyi pushed a commit that referenced this issue May 18, 2018
Part of #5072.

Overloads are probably the most common user-facing feature that still outputs "builtins" in error messages; this diff fixes them to use standard type formatting.

I also change builtins.None to None, since builtins.None is a syntax error. A comment claimed that we use builtins.None to distinguish the type from the value, but I don't think there are a lot of contexts where that confusion is likely.
JukkaL pushed a commit that referenced this issue Nov 11, 2021
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants