Skip to content

typeanal: add error codes for many errors #13550

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

Merged
merged 7 commits into from
Sep 8, 2022

Conversation

hauntsaninja
Copy link
Collaborator

I only added codes that I was fairly confident about

I only added codes that I was fairly confident about
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator Author

Hmm, mypy self check is fine, but the mypyc build fails. E.g., you can minimise this to:

λ git diff | cat            
Alias tip: gd | cat
diff --git a/mypy/message_registry.py b/mypy/message_registry.py
index 1b58f56d8..b6f49baab 100644
--- a/mypy/message_registry.py
+++ b/mypy/message_registry.py
@@ -26,6 +26,7 @@ class ErrorMessage(NamedTuple):
 
 
 # Invalid types
+ASDF: Final = ErrorMessage("yikes", codes.VALID_TYPE)
 INVALID_TYPE_RAW_ENUM_VALUE: Final = "Invalid type: try using Literal[{}.{}] instead?"
 
 # Type checker error message constants

λ mypy --config-file mypy_self_check.ini -p mypy -p mypyc     
Success: no issues found in 264 source files

λ CC=clang MYPYC_OPT_LEVEL=0 python3 setup.py --use-mypyc build_ext --inplace          
mypy/message_registry.py:29: error: Cannot determine type of "VALID_TYPE"

@github-actions

This comment has been minimized.

@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, looks good overall. Left comments about uses of the type-var error code, which didn't feel quite right to me.

mypy/typeanal.py Outdated
@@ -281,11 +281,13 @@ def visit_unbound_type_nonoptional(self, t: UnboundType, defining_literal: bool)
tvar_def = self.tvar_scope.get_binding(sym)
if isinstance(sym.node, ParamSpecExpr):
if tvar_def is None:
self.fail(f'ParamSpec "{t.name}" is unbound', t)
self.fail(f'ParamSpec "{t.name}" is unbound', t, code=codes.TYPE_VAR)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This arguably goes against the description of the error code: "Check that type variable values are valid". There's a similar existing use in checker.py which is also seems incorrect. Can we use valid-type here instead? We could add a new error code, such as typevar-bound (analogous to to name-defined), but this may be a little marginal for a dedicated error code.

mypy/typeanal.py Outdated
t,
code=codes.TYPE_VAR,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above, valid-type seems better here (or falling back to misc).

mypy/typeanal.py Outdated
t,
code=codes.TYPE_VAR,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above.

mypy/typeanal.py Outdated
)
return AnyType(TypeOfAny.from_error)
if isinstance(sym.node, TypeVarTupleExpr):
if tvar_def is None:
self.fail(f'TypeVarTuple "{t.name}" is unbound', t)
self.fail(f'TypeVarTuple "{t.name}" is unbound', t, code=codes.TYPE_VAR)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above.

self.fail(f'Type variable "{name}" is bound by an outer class', defn)
self.fail(
f'Type variable "{name}" is bound by an outer class', defn, code=codes.TYPE_VAR
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to above.

@hauntsaninja
Copy link
Collaborator Author

Thanks, I had based these off of the one in checker.py. Changed!

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@hauntsaninja hauntsaninja merged commit cc59b56 into python:master Sep 8, 2022
@hauntsaninja hauntsaninja deleted the typeanalcode branch September 8, 2022 03:37
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