Refactor extractors: Pythonic improvements, docstrings, and optimizations#730
Draft
AndyTheFactory with Copilot wants to merge 3 commits into
Draft
Refactor extractors: Pythonic improvements, docstrings, and optimizations#730AndyTheFactory with Copilot wants to merge 3 commits into
AndyTheFactory with Copilot wants to merge 3 commits into
Conversation
Agent-Logs-Url: https://github.com/AndyTheFactory/newspaper4k/sessions/0c3d85a0-d9b2-4638-83b3-e6b79589dc06 Co-authored-by: AndyTheFactory <863810+AndyTheFactory@users.noreply.github.com>
Agent-Logs-Url: https://github.com/AndyTheFactory/newspaper4k/sessions/8c0e3849-680a-4f64-b2d1-7dd92e9f3aae Co-authored-by: AndyTheFactory <863810+AndyTheFactory@users.noreply.github.com>
Agent-Logs-Url: https://github.com/AndyTheFactory/newspaper4k/sessions/8c0e3849-680a-4f64-b2d1-7dd92e9f3aae Co-authored-by: AndyTheFactory <863810+AndyTheFactory@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
AndyTheFactory
April 30, 2026 20:08
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reviewed and refactored all files in
newspaper/extractors/for readability, Pythonic style, correctness, and minor performance improvements.Changes
authors_extractor.pyuniqify_list,parse_byline,get_authors,get_text_from_element) out ofparse()and into proper class/static methods_DIGITS_RE,_author_stopwords_re) at class level to avoid recompiling on everyparse()callOrderedDictwith plaindict(ordered since Python 3.7) — removes an unnecessary importmwas reused for both a regex match and a loop variable)contentfromstr | list[str]to juststrpubdate_extractor.pyparse_date_strclosure to a proper_parse_date_strclass methoddate_strlocal variables where the value was only used oncecategories_extractor.pyset.isdisjoint()instead oflen(set.intersection()) == 0(more readable and marginally faster)(x != "http" and x != "https")with idiomaticx not in ("http", "https")not _valid_categoriesinstead oflen(_valid_categories) == 0content_extractor.pyget_feed_urlsfrom a multi-step loop + list + dedup pipeline into a clean set-comprehension__init__docstringsarticlebody_extractor.pysum()instead of building intermediate lists (reduces memory allocation)add_siblingswhich was missing theres_node = copy.deepcopy(top_node)assignmentD100,D101,D102)videos_extractor.pygetattr(self, ..., None)for safe method dispatch — avoids a potentialAttributeErrorif an unknown video tag is encountered__init__docstringsimage_extractor.py/metadata_extractor.py/title_extractor.py__init__docstringsparsedocstring inimage_extractor.pyto document all argumentsdefines.pyMetaImageDictclass docstring; restored accidentally missingtag: strfieldValidation
ruff check newspaper/extractors/— ✅ All checks passedpytest tests/unit/— ✅ 128 tests pass (10 pre-existing failures from missing optional dependencies: nltk, pythainlp, indic-nlp-library)