Skip to content

Modernize codebase with type hints, linting, and Python 3.8+ support#13

Open
typpo wants to merge 1 commit into
masterfrom
claude/quickchart-py-modernize-okv5p3
Open

Modernize codebase with type hints, linting, and Python 3.8+ support#13
typpo wants to merge 1 commit into
masterfrom
claude/quickchart-py-modernize-okv5p3

Conversation

@typpo

@typpo typpo commented Jun 29, 2026

Copy link
Copy Markdown
Owner

This PR modernizes the quickchart-python codebase with comprehensive type hints, updated tooling, and improved code quality standards.

Summary

The codebase has been updated to use modern Python practices including inline type hints (PEP 561), ruff for linting and formatting, and a modernized project configuration. Support for Python 3.7 has been dropped in favor of Python 3.8+.

Key Changes

Type Hints & Code Quality:

  • Added comprehensive type hints throughout quickchart/__init__.py using typing module
  • Added py.typed marker file for PEP 561 compliance
  • Replaced Python 2 compatibility code (try/except for urllib imports)
  • Modernized string formatting to use f-strings throughout

Configuration & Packaging:

  • Migrated pyproject.toml from Poetry-only format to PEP 621 [project] metadata
  • Updated build backend to poetry.core.masonry.api
  • Added PEP 735 dependency groups for dev tools
  • Bumped minimum Python version from 3.7 to 3.8
  • Added classifiers for Python 3.8-3.13 support

Tooling & CI/CD:

  • Replaced Travis CI with GitHub Actions workflow (.github/workflows/ci.yml)
  • Replaced autopep8 with ruff for linting and formatting
  • Updated scripts/format.sh to use ruff instead of autopep8
  • Added ruff configuration with appropriate rules and per-file ignores

Features:

  • Added configurable timeout parameter (default 60 seconds) to network requests
  • Derived User-Agent version from installed package metadata via importlib.metadata
  • Added _serialized_config() helper method to reduce code duplication

Testing:

  • Made network-dependent tests opt-in via QUICKCHART_NETWORK_TESTS environment variable
  • Updated test suite to use pytest instead of unittest runner
  • Reformatted all test code for consistency

Documentation:

  • Added CHANGELOG.md documenting changes in v2.1.0
  • Updated README.md with Python version requirements and development instructions
  • Updated CI badge from Travis to GitHub Actions

Code Formatting:

  • Applied consistent formatting across all example files
  • Reformatted all code to match ruff's style guidelines
  • Updated .gitignore to include .pytest_cache/ and .ruff_cache/

Notable Implementation Details

  • The timeout parameter defaults to 60 seconds and applies to all network requests (get_bytes(), get_short_url(), to_file())
  • Type hints use Optional and Union from typing module rather than PEP 604 syntax (X | Y) to maintain Python 3.8 compatibility
  • Network tests are skipped by default to keep the test suite deterministic and offline-friendly

https://claude.ai/code/session_01LDLZoKFv4Y4Q6rFYMn4MoL

Bring the library up to date after a long gap:

Packaging
- Migrate pyproject.toml to PEP 621 [project] metadata with the
  poetry.core.masonry.api build backend and PEP 735 dependency groups.
- Drop end-of-life Python 3.7; minimum is now Python 3.8. Add classifiers
  for 3.8 through 3.13.
- Ship type hints plus a py.typed marker (PEP 561).

Client code
- Add a configurable request timeout (default 60s) so network calls no
  longer hang indefinitely.
- Remove Python 2 compatibility shims, use isinstance checks and f-strings,
  import requests at module load, and add type annotations.
- Derive the User-Agent version from installed package metadata.

CI and tooling
- Replace Travis with a GitHub Actions matrix (Python 3.8-3.13).
- Replace autopep8 with ruff for linting and formatting.
- Make the live-service test opt-in via QUICKCHART_NETWORK_TESTS so the
  default suite is deterministic and offline-friendly.

Docs
- Update README badges, version notes, timeout docs, and add a Development
  section. Add CHANGELOG.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LDLZoKFv4Y4Q6rFYMn4MoL
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