-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
I only added codes that I was fairly confident about
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hmm, mypy self check is fine, but the mypyc build fails. E.g., you can minimise this to:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to above.
Thanks, I had based these off of the one in checker.py. Changed! |
This comment has been minimized.
This comment has been minimized.
1 similar comment
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
I only added codes that I was fairly confident about