-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Sourcery refactored master branch #107
Conversation
attempt = try_date_expr( | ||
if attempt := try_date_expr( | ||
text, outputformat, extensive_search, min_date, max_date | ||
) | ||
if attempt: | ||
): | ||
return attempt | ||
# try link title (Blogspot) | ||
title_attr = trim_text(elem.get("title", "")) | ||
if len(title_attr) > MIN_SEGMENT_LEN: | ||
title_attr = NON_DIGITS_REGEX.sub("", title_attr[:MAX_SEGMENT_LEN]) | ||
attempt = try_date_expr( | ||
if attempt := try_date_expr( | ||
title_attr, outputformat, extensive_search, min_date, max_date | ||
) | ||
if attempt: | ||
): |
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.
Function examine_date_elements
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×2] (
use-named-expression
)
year_match = yearpat.search(pattern) | ||
if year_match: | ||
if year_match := yearpat.search(pattern): |
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.
Function select_candidate
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
year = "19" + year if year[0] == "9" else "20" + year | ||
year = f"19{year}" if year[0] == "9" else f"20{year}" |
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.
Function normalize_match
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
month = "0" + month | ||
month = f"0{month}" |
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.
Function search_page
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
@@ -3,6 +3,7 @@ | |||
Custom parsers and XPath expressions for date extraction | |||
""" | |||
|
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.
Lines 88-88
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
match = COMPLETE_URL.search(testurl) | ||
if match: | ||
if match := COMPLETE_URL.search(testurl): |
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.
Function extract_url_date
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
# 2. Try YYYYMMDD, use regex | ||
match = YMD_NO_SEP_PATTERN.search(string) | ||
if match: | ||
if match := YMD_NO_SEP_PATTERN.search(string): |
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.
Function custom_parse
refactored with the following changes:
- Use named expression to simplify assignment and conditional [×3] (
use-named-expression
)
This removes the following comments ( why? ):
# 4. Try the Y-M and M-Y patterns
# 2. Try YYYYMMDD, use regex
# 3. Try the very common YMD, Y-M-D, and D-M-Y patterns
match = TEXT_PATTERNS.search(htmlstring) # EN+DE+TR | ||
if match: | ||
if match := TEXT_PATTERNS.search(htmlstring): | ||
parts = list(filter(None, match.groups())) | ||
if len(parts) == 3: | ||
candidate = None | ||
if len(parts[0]) == 4: | ||
candidate = datetime(int(parts[0]), int(parts[1]), int(parts[2])) | ||
elif len(parts[2]) in (2, 4): | ||
elif len(parts[2]) in {2, 4}: |
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.
Function idiosyncrasies_search
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Use set when checking membership of a collection of literals (
collection-into-set
)
This removes the following comments ( why? ):
# EN+DE+TR
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!