Skip to content

Sync python-import with the full update of Python import - #894

Merged
realpython-bot merged 5 commits into
masterfrom
maintenance/python-import-20261018
Oct 22, 2026
Merged

realpython-bot merged 5 commits into
masterfrom
maintenance/python-import-20261018

Conversation

@realpython-bot

@realpython-bot realpython-bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Companion to the full update of Python import: Advanced Techniques and Tips.

What changed

  • population_quiz/population_quiz.py: random.sample(population.keys(), ...) raises TypeError since Python 3.11. It now passes list(population).
  • plugins.py: importlib.resources.contents() is deprecated since Python 3.11. _import_all() now uses resources.files(package).iterdir().
  • population_quiz/population_quiz.py, population.py: read the UN WPP2024 file through resources.files("data"), since the WPP2019 download is gone. The Python 3.7 importlib_resources fallback is removed.
  • hello_gui/__main__.py: resources.path() is replaced by files() and as_file(), matching the article.
  • structure/: setup.cfg and setup.py are replaced by a minimal pyproject.toml, following learner feedback.
  • population_quiz/data/README.md: points at the WPP2024 download and explains the unzip step.
  • README.md: lists the tested Python versions and the pinned install command.

Links

Verification (Python 3.15.1, spot checks on 3.14.9; PyYAML 6.0.3, matplotlib 3.11.2, colorama 0.4.6)

  • population_quiz.py ran a full quiz against the real WPP2024 CSV, and it also runs as a zipapp archive.
  • population.py loads the data and orders countries for 2050.
  • greeter plugins work with -W error.
  • hello_gui opens and closes under Xvfb.
  • python -m pip install -e . in structure/ works with the new pyproject.toml, and cli.py runs afterwards.
  • uvx ruff@0.14.1 format --check python-import and uvx ruff@0.14.1 check python-import pass.

🤖 Generated with Claude Code

realpython-bot and others added 3 commits October 18, 2026 06:12
…nced Techniques and Tips

- population_quiz.py: pass list(population) to random.sample(), which no longer accepts dict views (Python 3.11+)
- plugins.py: replace deprecated importlib.resources.contents() with files().iterdir()

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- structure/: replace setup.cfg and setup.py with a minimal pyproject.toml
- population_quiz.py, population.py: read the UN WPP2024 file with
  importlib.resources.files() and drop the Python 3.7 backport fallback
- hello_gui/__main__.py: use files() and as_file() instead of path()
- population_quiz/data/README.md: point at the WPP2024 download
- README.md: list tested Python versions and pinned dependencies

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@realpython-bot realpython-bot changed the title Sync python-import with the updated tutorial Sync python-import with the full update of Python import Oct 22, 2026
martin-martin and others added 2 commits October 22, 2026 15:47
population.py loads its CSV file through importlib.resources from the
`data` package, which lives in population_quiz/. From the folder root,
`import population` failed with ModuleNotFoundError. The README now also
spells out the setup steps for the examples that need them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@realpython-bot
realpython-bot merged commit 18a5a4a into master Oct 22, 2026
1 check passed
@realpython-bot
realpython-bot deleted the maintenance/python-import-20261018 branch October 22, 2026 15:59
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.

2 participants