-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
stubtest: if a default is present in the stub, check that it is correct #14085
Conversation
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, had one quick comment!
I guess given we want to restrict to simple values in typeshed, the biggest hole here is enums. You can get at the symbol table using get_stub
, but you'll probably have to look up the runtime to get the actual enum value.
mypy/stubtest.py
Outdated
@@ -573,6 +753,23 @@ def _verify_arg_default_value( | |||
f"has a default value of type {runtime_type}, " | |||
f"which is incompatible with stub argument type {stub_type}" | |||
) | |||
if runtime_arg.default is not ... and stub_arg.initializer is not None: |
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.
Why do we have runtime_arg.default is not ...
here? (clause looks untested as well)
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.
Yes, I don't think I need that check. Will remove.
Not sure how to fix the mypyc failure. |
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.
Maybe try class _NodeEvaluator(object, ExpressionVisitor[object]):
?
If that doesn't work, maybe just preserve the generic: class _NodeEvaluator(Generic[T], ExpressionVisitor[T]):
mypy/stubtest.py
Outdated
@@ -540,6 +543,186 @@ def names_approx_match(a: str, b: str) -> bool: | |||
) | |||
|
|||
|
|||
class _NodeEvaluator(ExpressionVisitor[object]): |
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.
class _NodeEvaluator(ExpressionVisitor[object]): | |
class _NodeEvaluator(object, ExpressionVisitor[object]): |
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.
Tried that, it doesn't even work without mypyc because it creates an inconsistent MRO. I'll try the generic way you suggested instead.
Now it segfaults instead. Progress! |
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.
Oh interesting. I guess we'll see what happens when we need to hook into more stubtest things to get enums to work out. There are enough "unknown"s here that I wouldn't feel bad about using an if statement instead of a visitor.
Feel free to merge when you get things green!
Yes, a visitor feels like the clean solution here but with so many unknowns, it's pretty ugly. |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Helps with python/typeshed#8988.