stubtest: if a default is present in the stub, check that it is correct#14085
stubtest: if a default is present in the stub, check that it is correct#14085JelleZijlstra merged 8 commits intopython:masterfrom
Conversation
hauntsaninja
left a comment
There was a problem hiding this comment.
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.
| 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.
Why do we have runtime_arg.default is not ... here? (clause looks untested as well)
There was a problem hiding this comment.
Yes, I don't think I need that check. Will remove.
|
Not sure how to fix the mypyc failure. |
hauntsaninja
left a comment
There was a problem hiding this comment.
Maybe try class _NodeEvaluator(object, ExpressionVisitor[object]):?
If that doesn't work, maybe just preserve the generic: class _NodeEvaluator(Generic[T], ExpressionVisitor[T]):
| ) | ||
|
|
||
|
|
||
| class _NodeEvaluator(ExpressionVisitor[object]): |
There was a problem hiding this comment.
| class _NodeEvaluator(ExpressionVisitor[object]): | |
| class _NodeEvaluator(object, ExpressionVisitor[object]): |
There was a problem hiding this comment.
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.
hauntsaninja
left a comment
There was a problem hiding this comment.
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.