Sub topic 2
Confirm Behavior in Versioned Docs and Changelogs
Assume you can read Python library documentation, install packages, and run unit tests. Generated code needs verification against the exact versions in your project. A current documentation page may describe an API that differs from the version you have installed.
Confirm behavior in versioned docs and changelogs
First identify the installed version:
from importlib.metadata import version
print(version("pandas"))Open the documentation for that version, then check the function or method directly. Read its parameter list, return value, and examples. Search the changelog for removals, renames, behavior changes, and deprecations.
For example, DataFrame.append appeared in older pandas examples but was removed in pandas 2.0. Generated code using it may look familiar while failing in a current environment. Replace it with a supported pattern:
import pandas as pd
rows = [{"id": 1}, {"id": 2}]
frame = pd.DataFrame(rows)
print(frame)Let type checkers and linters flag missing attributes
Static analysis examines code without running every path. A type checker such as mypy can report an attribute or keyword that does not exist in the library's type information. A linter can catch deprecated patterns when a suitable rule or plugin is enabled.
Run analysis in the same environment as the application:
python -m mypy src/
python -m ruff check src/Treat missing-attribute and invalid-argument findings as review blockers. Type stubs can lag behind a library, so confirm important findings in the versioned documentation.
Turn deprecation warnings into failures
Deprecation warnings announce that code still works but may be removed. Make them visible during tests:
python -W error::DeprecationWarning -m pytestThis turns a warning into a failing test. Fix the call, consult the migration notes, and keep the test so the old usage cannot silently return.
Exercise
Why should you check both the installed version and the changelog?
Show answer
The installed version determines what can run, while the changelog explains removals, renamed APIs, and behavior changes between releases.