Skip to content

Instantly share code, notes, and snippets.

@jonafato
Last active May 6, 2025 17:03
Show Gist options
  • Select an option

  • Save jonafato/6f8d18582007d1c9e94d9dd185d8f83a to your computer and use it in GitHub Desktop.

Select an option

Save jonafato/6f8d18582007d1c9e94d9dd185d8f83a to your computer and use it in GitHub Desktop.

Revisions

  1. jonafato revised this gist May 6, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion patch_version_info.py
    Original file line number Diff line number Diff line change
    @@ -14,4 +14,4 @@ class version_info(NamedTuple): # noqa: N801

    sys.version_info = version_info(*str(math.pi).split('.'), *sys.version_info[2:])

    # sys.version_info is now version_info(major='3', minor='141592653589793', micro=2, releaselevel=1, serial=0)
    # sys.version_info is now version_info(major='3', minor='141592653589793', micro=0, releaselevel='alpha', serial=6)
  2. jonafato revised this gist May 6, 2025. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion patch_version_info.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    import math
    import sys
    from typing import NamedTuple

    @@ -11,4 +12,6 @@ class version_info(NamedTuple): # noqa: N801
    releaselevel: Literal["alpha", "beta", "candidate", "final"]
    serial: int #: Serial release number

    sys.version_info = version_info(*sys.version_info)
    sys.version_info = version_info(*str(math.pi).split('.'), *sys.version_info[2:])

    # sys.version_info is now version_info(major='3', minor='141592653589793', micro=2, releaselevel=1, serial=0)
  3. jonafato created this gist May 6, 2025.
    14 changes: 14 additions & 0 deletions patch_version_info.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    import sys
    from typing import NamedTuple

    # Copy the helper class from the Doc directory to represent a createable version_info class
    # https://github.com/python/cpython/blob/3dfed230928de0f649061782a36691066a0ef058/Doc/tools/extensions/patchlevel.py#L25-L30

    class version_info(NamedTuple): # noqa: N801
    major: int #: Major release number
    minor: int #: Minor release number
    micro: int #: Patch release number
    releaselevel: Literal["alpha", "beta", "candidate", "final"]
    serial: int #: Serial release number

    sys.version_info = version_info(*sys.version_info)