Skip to content

Fix importing dateparser_data.settings before dateparser - #1562

Merged
serhii73 merged 1 commit into
scrapinghub:masterfrom
serhii73:fix-parts-of-day-circular-import
Nov 4, 2026
Merged

serhii73 merged 1 commit into
scrapinghub:masterfrom
serhii73:fix-parts-of-day-circular-import

Conversation

@serhii73

@serhii73 serhii73 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

from dateparser_data.settings import default_parsers, the import shown in the settings documentation, raises AttributeError: partially initialized module 'dateparser_data.settings' has no attribute 'settings' (most likely due to a circular import) when it is the first import of the process. It works in 1.4.3 and when dateparser is imported first, which is why the test suite does not notice.

Since #1473, dateparser_data/settings.py imports dateparser._parts_of_day, which makes it import the dateparser package, which reads settings.settings back while that module is still being executed.

This adds the PARTS_OF_DAY default where the module is read (Settings._get_settings_from_pyfile) instead, so that dateparser_data.settings no longer imports dateparser. Settings adds the default to the module's dictionary when it first reads it; nothing else in the package or the docs reads that key from the module.

The new test imports the module in a fresh interpreter, because in the test process dateparser is always imported already. It fails without the change and passes with it.

Checked with a local mirror of the CI matrix (16 legs): Python 3.10 to 3.15 (3.13 also with TZ=Pacific/Auckland and TZ=Pacific/Fiji), the minimum supported dependency versions (with and without the optional ones), all optional dependencies, mypy, the docs build, the scripts, the benchmarks, twine check and the pinned pre-commit hooks. All pass.

πŸ€– Generated with Claude Code

from dateparser_data.settings import default_parsers, the import shown in the
documentation, raised AttributeError when it was the first import in the
process: dateparser_data/settings.py imported dateparser._parts_of_day, which
made it import the dateparser package, which reads settings.settings back
while that module was still being executed.

Add the PARTS_OF_DAY default where the settings module is read instead, so that
dateparser_data.settings no longer imports dateparser, and test the import in a
fresh interpreter.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 99.19%. Comparing base (2d93cdc) to head (9722cd7).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1562   +/-   ##
=======================================
  Coverage   99.19%   99.19%           
=======================================
  Files         239      239           
  Lines        4098     4099    +1     
=======================================
+ Hits         4065     4066    +1     
  Misses         33       33           

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 3, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

βœ… 10 untouched benchmarks


Comparing serhii73:fix-parts-of-day-circular-import (9722cd7) with master (2d93cdc)

Open in CodSpeed

@serhii73
serhii73 merged commit 16ee000 into scrapinghub:master Nov 4, 2026
20 checks passed
@serhii73
serhii73 deleted the fix-parts-of-day-circular-import branch November 4, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant