Repository navigation
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.
noviluni
left a comment
There was a problem hiding this comment.
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.
|
|
||
| # 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.
@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:
searchfunctionality 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.