-
Notifications
You must be signed in to change notification settings - Fork 467
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
Reducing cyclomatic complexity of search and addressing offset awareness issue #881
Conversation
* fix: scoping where the language is retrieved * chore: reduce cyclomatic complexity and indentation on complicated code
Codecov Report
@@ Coverage Diff @@
## master #881 +/- ##
==========================================
+ Coverage 98.15% 98.20% +0.04%
==========================================
Files 229 229
Lines 2495 2504 +9
==========================================
+ Hits 2449 2459 +10
+ Misses 46 45 -1
Continue to review full report at Codecov.
|
Oooo, ok. I'll add an additional test here. |
hey @noviluni So seems like the CC is complaining because I haven't hit this line. Totally understand. Here's the problem... after code tracing, it doesn't seem that Thoughts? |
What about adding an assert for |
Great idea! Totally forgot about using an assert here. Changing it now. |
… that future maintainers can address this if the condition becomes possible.
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.
Hey @SimplicityGuy! Good job here!
The search
functionality has to be refactored and checked because it is hard to read and there are a bunch of known bugs: https://github.com/scrapinghub/dateparser/issues?q=is%3Aissue+is%3Aopen+label%3Asearch_dates
Thank you very much for addressing this! I left one minor comment.
dateparser/parser.py
Outdated
@@ -447,6 +448,19 @@ def _correct_for_time_frame(self, dateobj): | |||
|
|||
dateobj = dateobj + delta | |||
|
|||
# NOTE: If this assert fires, self.now needs to be made offset-aware in a similar | |||
# way that dateobj is temporarily made offset-aware. | |||
assert not (self.now.tzinfo is None and dateobj.tzinfo is not None), "Review comment for details." |
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.
@SimplicityGuy
I know that it doesn't seem to happen, but Imagine we introduce the bug without noticing and some user gets this error. I think we should do the error message a bit more self-explanatory. What about something like...?:
assert not (self.now.tzinfo is None and dateobj.tzinfo is not None), "Review comment for details." | |
assert not (self.now.tzinfo is None and dateobj.tzinfo is not None), "`self.now` shouldn't have tzinfo. Review comment in code for details." |
or
assert not (self.now.tzinfo is None and dateobj.tzinfo is not None), "Review comment for details." | |
assert not (self.now.tzinfo is None and dateobj.tzinfo is not None), "Timezone info is wrong. Review comment in code for details." |
In that way, people affected by this (either developers or users) will be able to provide more context if they find this error.
@Gallaecio let me know what you think
Thank you! |
Includes 2 contributions:
search
functionality is complex, the first change addresses cyclomatic complexity and deep indentation in the search code. This should make the code easier to read and maintain.