-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update typecheck err msg #32880
Update typecheck err msg #32880
Conversation
There are still some failing tests that are just checking the error string. Before spending more time fixing them, I'd like to see what people think of this error message first. |
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
assign set of reviewers |
Assigning reviewers. If you would like to opt out of this review, comment R: @shunping for label python. Available commands:
The PR bot will only process comments in the main thread (not review comments). |
Bump @shunping @chamikaramj , could I get your quick feedback on just the error message here (no need to look at the code yet)? If it looks good, I'll fix up the rest of the tests and wait for another round of approval |
@hjtran, I totally agree with you. I myself encountered a similar situation recently, and I think it is a great idea to simplify the error message and give cx a better experience. Thanks for contributing! + @jrmccluskey, who is our expert of python typehint, for any more advice. |
arg_hints = iter(hints.items()) | ||
element_arg, element_hint = next(arg_hints) | ||
if not typehints.is_consistent_with( | ||
bindings.get(element_arg, typehints.Any), element_hint): | ||
transform_nest_level = self.label.count("/") | ||
split_producer_label = pvalueish.producer.full_label.split("/") | ||
producer_label = "/".join( | ||
split_producer_label[:transform_nest_level + 1]) | ||
raise TypeCheckError( | ||
f"The transform '{self.label}' requires " | ||
f"PCollections of type '{element_hint}' " | ||
f"but was applied to a PCollection of type" | ||
f" '{bindings[element_arg]}' " | ||
f"(produced by the transform '{producer_label}'). ") |
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.
Is there a reason this type check is done up here rather than modifying the check nested in the for loop? It looks kind of redundant here.
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.
Yeah this is specifically a check for the main element while the loop is checking presumably side inputs.
sdks/python/pyproject.toml
Outdated
@@ -26,7 +26,7 @@ requires = [ | |||
# Avoid https://github.com/pypa/virtualenv/issues/2006 | |||
"distlib==0.3.7", | |||
# Numpy headers | |||
"numpy>=1.14.3,<2.2.0", # Update setup.py as well. | |||
"numpy>=1.14.3,<1.27", # Update setup.py 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.
Please revert this change (I'm assuming this was unintentional)
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.
Huh, yeah I didn't change this intentionally. Maybe weird git operation artifact. Reverting
I definitely like the new form factor for the error, that's much cleaner. I've gotten decently good at parsing the current messages since I've been in and around the typehinting code a lot, but making it more clear for users is a big win (and may also make my life easier when I do more typehinting updates.) |
|
||
expected_msg = \ | ||
"Type hint violation for 'CombinePerKey': " \ | ||
"requires Tuple[TypeVariable[K], Union[<class 'float'>, <class 'int'>, " \ | ||
"<class 'numpy.float64'>, <class 'numpy.int64'>]] " \ | ||
"but got Tuple[None, <class 'str'>] for element" | ||
|
||
self.assertStartswith(e.exception.args[0], expected_msg) |
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 and one of the other messages got too hard/frustrating to update to use with regex, so I just did some basic spot checking. The number of cases that the new asserts wouldn't catch but the old would I think are pretty few.
Bump @jrmccluskey |
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.
LGTM, thank you!
The error message for applying a pcollection of incorrect type to a PTransform is really long and difficult to parse. For example, with this pipeline:
The error message is:
This error message is really long and the extra "based on..." context (in my experience and the users I've talked to's experience) hasn't been helpful in figuring out the issue.
When there's a type hint issue, I want to know:
I've simplified the error message to answer those questions a bit more directly, so now the above example produces the following error message:
I've only applied this change to type hint violations for the main input, not for side inputs which I've left alone (though I think the "based on..." messages probably aren't useful there either)