Skip to content

Commit 7347a23

Browse files
Merge branch 'main' into cythonize
2 parents 5fe8344 + 66584dc commit 7347a23

9 files changed

Lines changed: 44 additions & 28 deletions

File tree

.github/workflows/cis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
run: |
7171
tox
7272
- name: Upload coverage to Codecov
73-
uses: codecov/codecov-action@v5
73+
uses: codecov/codecov-action@v6
7474
if: github.event_name != 'schedule'
7575
with:
7676
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
pip install dist/*.tar.gz
3434
python -X dev -m pytest tests
3535
- name: Store artifacts
36-
uses: actions/upload-artifact@v6
36+
uses: actions/upload-artifact@v7
3737
with:
3838
name: cibw-sdist
3939
path: dist/*
@@ -65,7 +65,7 @@ jobs:
6565
pip install dist/*.whl
6666
python -X dev -m pytest tests
6767
- name: Store artifacts
68-
uses: actions/upload-artifact@v6
68+
uses: actions/upload-artifact@v7
6969
with:
7070
name: cibw-wheel-pure
7171
path: dist/*.whl
@@ -108,7 +108,7 @@ jobs:
108108
id-token: write
109109
steps:
110110
- name: Download all the dists
111-
uses: actions/download-artifact@v7.0.0
111+
uses: actions/download-artifact@v8.0.1
112112
with:
113113
pattern: cibw-*
114114
path: dist
@@ -130,13 +130,13 @@ jobs:
130130

131131
steps:
132132
- name: Download all the dists
133-
uses: actions/download-artifact@v7.0.0
133+
uses: actions/download-artifact@v8.0.1
134134
with:
135135
pattern: cibw-*
136136
path: dist
137137
merge-multiple: true
138138
- name: Sign the dists with Sigstore
139-
uses: sigstore/gh-action-sigstore-python@v3.2.0
139+
uses: sigstore/gh-action-sigstore-python@v3.3.0
140140
with:
141141
inputs: >-
142142
./dist/*.tar.gz

.readthedocs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ version: 2
77

88
# Set the version of Python and other tools you might need
99
build:
10-
os: ubuntu-20.04
10+
os: ubuntu-24.04
1111
tools:
12-
python: "3.9"
12+
python: "3.12"
1313

1414
# Build documentation in the docs/source directory with Sphinx
1515
sphinx:

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ unreleased: Version 0.18.0
55
--------------------------
66

77
- drop support for Python 3.9 and 3.10 PR #180
8+
- Replace string literal type annotations with postponed evaluation using
9+
``from __future__ import annotations`` PR #191
810

911
Bugfixes:
1012

src/bytecode/bytecode.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# alias to keep the 'bytecode' variable free
1+
from __future__ import annotations
2+
23
import types
34
from abc import abstractmethod
45
from typing import (
@@ -15,6 +16,7 @@
1516
overload,
1617
)
1718

19+
# alias to keep the 'bytecode' variable free
1820
import bytecode as _bytecode
1921
from bytecode.flags import CompilerFlags, infer_flags
2022
from bytecode.instr import (
@@ -48,7 +50,7 @@ def __init__(self) -> None:
4850
self.freevars: List[str] = []
4951
self._flags: CompilerFlags = CompilerFlags(0)
5052

51-
def _copy_attr_from(self, bytecode: "BaseBytecode") -> None:
53+
def _copy_attr_from(self, bytecode: BaseBytecode) -> None:
5254
self.argcount = bytecode.argcount
5355
self.posonlyargcount = bytecode.posonlyargcount
5456
self.kwonlyargcount = bytecode.kwonlyargcount
@@ -275,7 +277,7 @@ def from_code(
275277
code: types.CodeType,
276278
prune_caches: bool = True,
277279
conserve_exception_block_stackdepth: bool = False,
278-
) -> "Bytecode":
280+
) -> Bytecode:
279281
concrete = _bytecode.ConcreteBytecode.from_code(code)
280282
return concrete.to_bytecode(
281283
prune_caches=prune_caches,
@@ -317,7 +319,7 @@ def to_concrete_bytecode(
317319
self,
318320
compute_jumps_passes: Optional[int] = None,
319321
compute_exception_stack_depths: bool = True,
320-
) -> "_bytecode.ConcreteBytecode":
322+
) -> _bytecode.ConcreteBytecode:
321323
converter = _bytecode._ConvertBytecodeToConcrete(self)
322324
return converter.to_concrete_bytecode(
323325
compute_jumps_passes=compute_jumps_passes,

src/bytecode/cfg.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import types
24
from collections import defaultdict
35
from dataclasses import dataclass
@@ -36,7 +38,7 @@ def __init__(
3638
] = None,
3739
) -> None:
3840
# a BasicBlock object, or None
39-
self.next_block: Optional["BasicBlock"] = None
41+
self.next_block: Optional[BasicBlock] = None
4042
if instructions:
4143
super().__init__(instructions)
4244

@@ -129,7 +131,7 @@ def legalize(self, first_lineno: int) -> int:
129131

130132
return current_lineno
131133

132-
def get_jump(self) -> Optional["BasicBlock"]:
134+
def get_jump(self) -> Optional[BasicBlock]:
133135
if not self:
134136
return None
135137

@@ -243,7 +245,7 @@ def __init__(
243245
self.pending_try_begin = pending_try_begin
244246
self._current_try_begin = pending_try_begin
245247

246-
def run(self) -> Generator[Union["_StackSizeComputer", int], int, None]:
248+
def run(self) -> Generator[Union[_StackSizeComputer, int], int, None]:
247249
"""Iterate over the block instructions to compute stack usage."""
248250
# Blocks are not hashable but in this particular context we know we won't be
249251
# modifying blocks in place so we can safely use their id as hash rather than
@@ -343,9 +345,11 @@ def run(self) -> Generator[Union["_StackSizeComputer", int], int, None]:
343345
None,
344346
# Do not propagate the TryBegin if a final instruction is followed
345347
# by a TryEnd.
346-
None
347-
if instr.is_final() and self.block.get_trailing_try_end(i)
348-
else self._current_try_begin,
348+
(
349+
None
350+
if instr.is_final() and self.block.get_trailing_try_end(i)
351+
else self._current_try_begin
352+
),
349353
)
350354

351355
# Update the maximum used size by the usage implied by the following
@@ -362,8 +366,10 @@ def run(self) -> Generator[Union["_StackSizeComputer", int], int, None]:
362366
# start with a TryEnd relevant only when reaching this block
363367
# through a particular jump. So we are lenient here.
364368
if (
365-
te := self.block.get_trailing_try_end(i)
366-
) and te.entry is self._current_try_begin:
369+
(te := self.block.get_trailing_try_end(i))
370+
and self._current_try_begin is not None
371+
and te.entry is self._current_try_begin
372+
):
367373
assert isinstance(te.entry.target, BasicBlock)
368374
yield from self._compute_exception_handler_stack_usage(
369375
te.entry.target,
@@ -426,7 +432,7 @@ def _update_size(self, pre_delta: int, post_delta: int) -> None:
426432

427433
def _compute_exception_handler_stack_usage(
428434
self, block: BasicBlock, push_lasti: bool
429-
) -> Generator[Union["_StackSizeComputer", int], int, None]:
435+
) -> Generator[Union[_StackSizeComputer, int], int, None]:
430436
b_id = id(block)
431437
if self.minsize < self.common.exception_block_startsize[b_id]:
432438
block_size = yield _StackSizeComputer(
@@ -737,7 +743,7 @@ def get_dead_blocks(self) -> List[BasicBlock]:
737743
return [b for b in self if id(b) not in seen_block_ids]
738744

739745
@staticmethod
740-
def from_bytecode(bytecode: _bytecode.Bytecode) -> "ControlFlowGraph":
746+
def from_bytecode(bytecode: _bytecode.Bytecode) -> ControlFlowGraph:
741747
# label => instruction index
742748
label_to_block_index = {}
743749
jumps = []

src/bytecode/concrete.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import dis
24
import inspect
35
import itertools
@@ -332,7 +334,7 @@ def __eq__(self, other: Any) -> bool:
332334
@staticmethod
333335
def from_code(
334336
code: types.CodeType, *, extended_arg: bool = False
335-
) -> "ConcreteBytecode":
337+
) -> ConcreteBytecode:
336338
instructions: MutableSequence[Union[SetLineno, ConcreteInstr]] = []
337339
for i in dis.get_instructions(code, show_caches=True):
338340
loc = InstrLocation.from_positions(i.positions) if i.positions else None

src/bytecode/instr.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import dis
24
import enum
35
import opcode as _opcode
@@ -267,7 +269,7 @@ class CommonConstant(enum.IntEnum):
267269
# This make type checking happy but means it won't catch attempt to manipulate an unset
268270
# statically. We would need guard on object attribute narrowed down through methods
269271
class _UNSET(int):
270-
instance: Optional["_UNSET"] = None
272+
instance: Optional[_UNSET] = None
271273

272274
def __new__(cls):
273275
if cls.instance is None:
@@ -611,7 +613,7 @@ def __init__(
611613
)
612614

613615
@classmethod
614-
def from_positions(cls, position: "dis.Positions") -> "InstrLocation": # type: ignore
616+
def from_positions(cls, position: dis.Positions) -> InstrLocation: # type: ignore
615617
return InstrLocation(
616618
position.lineno,
617619
position.end_lineno,
@@ -654,7 +656,7 @@ def __init__(
654656
self.push_lasti: bool = push_lasti
655657
self.stack_depth: int | _UNSET = stack_depth
656658

657-
def copy(self) -> "TryBegin":
659+
def copy(self) -> TryBegin:
658660
return TryBegin(self.target, self.push_lasti, self.stack_depth)
659661

660662

@@ -664,7 +666,7 @@ class TryEnd:
664666
def __init__(self, entry: TryBegin) -> None:
665667
self.entry: TryBegin = entry
666668

667-
def copy(self) -> "TryEnd":
669+
def copy(self) -> TryEnd:
668670
return TryEnd(self.entry)
669671

670672

tests/frameworks/module.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import abc
24
import sys
35
import typing as t
@@ -124,7 +126,7 @@ class BaseModuleWatchdog:
124126
Invokes ``after_import`` every time a new module is imported.
125127
"""
126128

127-
_instance: t.Optional["BaseModuleWatchdog"] = None
129+
_instance: t.Optional[BaseModuleWatchdog] = None
128130

129131
def __init__(self) -> None:
130132
self._finding: t.Set[str] = set()

0 commit comments

Comments
 (0)