{"record":{"id":"5c7f1bcf5ae57f67","repo":"sqlalchemy/alembic","slug":"script-supports-at-least-python-join-str-x-f","errorCode":null,"errorMessage":"Script supports at least python {\".\".join(str(x) for x in lower_python)} but less than {\".\".join(str(x) for x in upper_python)} right now.","messagePattern":"Script supports at least python (.+?) but less than (.+?) right now\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/write_pyi.py","lineNumber":70,"sourceCode":"    \"sqlalchemy.sql.schema.\",\n    \"sqlalchemy.sql.selectable.\",\n    \"sqlalchemy.sql.type_api.\",\n    \"typing.\",\n]\nADDITIONAL_ENV = {\n    \"MigrationContext\": MigrationContext,\n    \"AutogenContext\": AutogenContext,\n    \"DefaultImpl\": DefaultImpl,\n    \"MigrationInfo\": MigrationInfo,\n}\n\n\ndef generate_pyi_for_proxy(\n    file_info: FileInfo, destination_path: Path, ignore_output: bool\n):\n    lower_python, upper_python = PYTHON_VERSIONS\n    if sys.version_info < lower_python or sys.version_info >= upper_python:\n        raise RuntimeError(\n            f\"Script supports at least python \"\n            f\"{\".\".join(str(x) for x in lower_python)} \"\n            f\"but less than {\".\".join(str(x) for x in upper_python)} \"\n            \"right now.\"\n        )\n\n    progname = Path(sys.argv[0]).as_posix()\n    # When using an absolute path on windows, this will generate the correct\n    # relative path that shall be written to the top comment of the pyi file.\n    if Path(progname).is_absolute():\n        progname = Path(progname).relative_to(Path().cwd()).as_posix()\n\n    file_info.read_file()\n\n    cls = file_info.target\n    with open(destination_path, \"w\") as buf:\n        file_info.write_before(buf, progname)\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/5551b5d35f985c99cb8f1af2b3c526b050e4c059/tools/write_pyi.py#L52-L88","documentation":"Raised as RuntimeError by generate_pyi_for_proxy in tools/write_pyi.py when the running Python interpreter version is outside the supported window [lower_python, upper_python) defined by PYTHON_VERSIONS = (3,14), (3,16) at write_pyi.py:37. This is a build/dev tooling guard — write_pyi.py generates .pyi stub files for Alembic's proxy classes and is only valid on the Python versions those stubs target. Running it on an incompatible interpreter would produce incorrect type stubs.","triggerScenarios":"Running tools/write_pyi.py (e.g. via 'python tools/write_pyi.py' or a make/tox target) on a Python version less than 3.14 or >= 3.16. The check at write_pyi.py:69 compares sys.version_info against the PYTHON_VERSIONS tuple. This only affects developers contributing to Alembic who regenerate stub files, not end users.","commonSituations":"Contributing to Alembic and running the stub generation step with the wrong Python version. Local dev environment using system Python 3.12 or 3.13 when stubs require 3.14. CI configured with a Python version outside the supported range. After a Python version bump where PYTHON_VERSIONS wasn't updated.","solutions":["Install and use Python 3.14 (or whichever version is in the PYTHON_VERSIONS range) to run write_pyi.py.","Use pyenv or a version manager: pyenv install 3.14 && pyenv shell 3.14.","If you're a maintainer updating the supported range, update PYTHON_VERSIONS at write_pyi.py:37 to match.","If you don't need to regenerate stubs, skip this step — it's not part of normal Alembic usage."],"exampleFix":"# before\npython3.12 tools/write_pyi.py  # RuntimeError: supports 3.14 to <3.16\n\n# after\npyenv install 3.14.0\npyenv shell 3.14.0\npython tools/write_pyi.py","handlingStrategy":"validation","validationCode":"import sys\n\ndef is_supported_python_for_pyi(lower=(3,14), upper=(3,16)):\n    v = sys.version_info\n    return v >= lower and v < upper","typeGuard":"import sys\n\ndef can_run_write_pyi() -> bool:\n    \"\"\"Type guard: True if current Python can run write_pyi.py.\"\"\"\n    return (3, 14) <= sys.version_info < (3, 16)","tryCatchPattern":null,"preventionTips":["Check sys.version_info before running write_pyi.py.","Use pyenv or pyenv-win to install the exact Python version required for stub generation.","This tool is for Alembic contributors only — end users never need to run it."],"tags":["alembic","build-tooling","python-version","dev-contrib","runtimeerror"],"backgroundTag":null,"analyzedSha":"5551b5d35f985c99cb8f1af2b3c526b050e4c059","analyzedAt":"2026-08-11T01:38:46.612Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}