Skip to content

Commit

Permalink
Merge pull request #146 from MatthieuDartiailh/py313
Browse files Browse the repository at this point in the history
Add support for Python 3.13
  • Loading branch information
MatthieuDartiailh authored Oct 27, 2024
2 parents c2d97b6 + b50cc68 commit 63d32b5
Show file tree
Hide file tree
Showing 16 changed files with 577 additions and 201 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/cis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Install tools
run: |
python -m pip install --upgrade pip
Expand Down Expand Up @@ -52,6 +52,8 @@ jobs:
toxenv: py311
- python-version: "3.12"
toxenv: py312
- python-version: "3.13-dev"
toxenv: py313
steps:
- uses: actions/checkout@v4
- name: Get history and tags for SCM versioning to work
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frameworks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = ["typing_extensions;python_version<'3.10'"]
dynamic = ["version"]


[project.urls]
homepage = "https://github.com/MatthieuDartiailh/bytecode"
homepage = "https://github.com/MatthieuDartiailh/bytecode"
documentation = "https://bytecode.readthedocs.io/en/latest/"
repository = "https://github.com/MatthieuDartiailh/bytecode"
changelog = "https://github.com/MatthieuDartiailh/bytecode/blob/main/doc/changelog.rst"
repository = "https://github.com/MatthieuDartiailh/bytecode"
changelog = "https://github.com/MatthieuDartiailh/bytecode/blob/main/doc/changelog.rst"


[build-system]
requires = ["setuptools>=61.2", "wheel", "setuptools_scm[toml]>=3.4.3"]
requires = ["setuptools>=61.2", "wheel", "setuptools_scm[toml]>=3.4.3"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
Expand Down Expand Up @@ -60,23 +61,23 @@ __version__ = "{version}"
"""

[tool.ruff]
src = ["src"]
src = ["src"]
extend-exclude = ["tests/instruments/hardware/nifpga/scope_based"]
line-length = 88
line-length = 88

[tool.ruff.lint]
select = ["B", "C", "E", "F", "W", "B9", "I", "C90", "RUF"]
select = ["B", "C", "E", "F", "W", "B9", "I", "C90", "RUF"]
extend-ignore = ["E203", "E266", "E501", "F403", "F401", "RUF012"]

[tool.ruff.lint.isort]
combine-as-imports = true
combine-as-imports = true
extra-standard-library = ["opcode"]

[tool.ruff.lint.mccabe]
max-complexity = 42

[tool.mypy]
follow_imports = "normal"
follow_imports = "normal"
strict_optional = true

[tool.pytest.ini_options]
Expand Down
5 changes: 2 additions & 3 deletions src/bytecode/bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
TryBegin,
TryEnd,
)
from bytecode.utils import PY311


class BaseBytecode:
Expand Down Expand Up @@ -297,9 +298,7 @@ def to_code(
) -> types.CodeType:
# Prevent reconverting the concrete bytecode to bytecode and cfg to do the
# calculation if we need to do it.
if stacksize is None or (
sys.version_info >= (3, 11) and compute_exception_stack_depths
):
if stacksize is None or (PY311 and compute_exception_stack_depths):
cfg = _bytecode.ControlFlowGraph.from_bytecode(self)
stacksize = cfg.compute_stacksize(
check_pre_and_post=check_pre_and_post,
Expand Down
20 changes: 13 additions & 7 deletions src/bytecode/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from bytecode.concrete import ConcreteInstr
from bytecode.flags import CompilerFlags
from bytecode.instr import UNSET, Instr, Label, SetLineno, TryBegin, TryEnd
from bytecode.utils import PY310, PY311, PY313

T = TypeVar("T", bound="BasicBlock")
U = TypeVar("U", bound="ControlFlowGraph")
Expand Down Expand Up @@ -443,7 +444,7 @@ def _compute_exception_handler_stack_usage(
def _is_stacksize_computation_relevant(
self, block_id: int, fingerprint: Tuple[int, Optional[bool]]
) -> bool:
if sys.version_info >= (3, 11):
if PY311:
# The computation is relevant if the block was not visited previously
# with the same starting size and exception handler status than the
# one in use
Expand Down Expand Up @@ -519,10 +520,15 @@ def compute_stacksize(
# Starting with Python 3.10, generator and coroutines start with one object
# on the stack (None, anything is an error).
initial_stack_size = 0
if sys.version_info >= (3, 10) and self.flags & (
CompilerFlags.GENERATOR
| CompilerFlags.COROUTINE
| CompilerFlags.ASYNC_GENERATOR
if (
not PY313 # under 3.13+ RETURN_GENERATOR make this explicit
and PY310
and self.flags
& (
CompilerFlags.GENERATOR
| CompilerFlags.COROUTINE
| CompilerFlags.ASYNC_GENERATOR
)
):
initial_stack_size = 1

Expand Down Expand Up @@ -951,8 +957,8 @@ def to_bytecode(self) -> _bytecode.Bytecode:
# TryEnd/TryBegin pair which share the same target.
# In each case, we store the value found in the CFG and the value
# inserted in the bytecode.
last_try_begin: tuple[TryBegin, TryBegin] | None = None
last_try_end: tuple[TryEnd, TryEnd] | None = None
last_try_begin: Tuple[TryBegin, TryBegin] | None = None
last_try_end: Tuple[TryEnd, TryEnd] | None = None

for block in self:
if id(block) in used_blocks:
Expand Down
Loading

0 comments on commit 63d32b5

Please sign in to comment.