-
-
Notifications
You must be signed in to change notification settings - Fork 327
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
temporal: Fixed E722 in temporal_granularity #4926
Conversation
@petrasovaa I'm wondering if restricting the types of errors caught here is really helpful for that specific function. It is a function that is used to validate if the granularity string is valid or not. So, you take a large domain of possible argument values (and types), and narrow down to True or False, True being when it is valid. By restricting the error types of the try-catch, it means we would fall back to python's exceptions and tracebacks if there's some sort of errors that aren't handled. In normal cases, it wouldn't bother much, but here, the function is written to fallback to true, and returning false on selected errors, rather than being written to return true only when it is really valid. With this PRs, other errors that would have returned true would now either return true or generate an error here or somewhere else in the code. |
Also the test for relative time is only checking if the argument is convertible to int, not that it is an int precisely. int() will accept a string of integers (including negatives), or a float, but not a string of float. It will however accept a string of integers with leading spaces and trailing newline, as well as accept the underscore inside the number as used like a number litteral grouping symbol, and also valid hexadecimal, prefixed by 0x or not (like "FACE" or "0xface" which both represent 64206). https://docs.python.org/3/library/functions.html#int Is it what we expect here? Is that temporal granularity in relative time passed to a C function that wouldn't consider it valid? |
Good point. Since this is a validation function, it makes more sense to catch all exceptions and return False for any invalid input rather than letting some exceptions propagate. I could only find potential |
This issue is addressed in #3748 , is this separate PR reqd or do I close this? |
#3748 is (or was initially) kinda big, and doesn't seem close to be finished if the trend continues. I don't think the author is active to continue adjusting it (it was for her job). This PR here is easier and faster to review and merge, so we might as well finish it off here |
I see your point, but realistically, there is not that much that can happen here, I would add the missing AttributeError there and move on. |
Add specific exceptions for E722 in
temporal_granularity.py
i.eValueError
. Didn't addTypeError
forNone
objects which seemed less likely to occur via code error.