mirror of
https://github.com/gumyr/build123d.git
synced 2026-04-27 23:31:39 -07:00
Merge pull request #1248 from DaWeidmann/patch-2-1
Some checks failed
benchmarks / benchmarks (macos-14, 3.12) (push) Has been cancelled
benchmarks / benchmarks (macos-15-intel, 3.12) (push) Has been cancelled
benchmarks / benchmarks (ubuntu-latest, 3.12) (push) Has been cancelled
benchmarks / benchmarks (windows-latest, 3.12) (push) Has been cancelled
Upload coverage reports to Codecov / run (push) Has been cancelled
pylint / lint (3.10) (push) Has been cancelled
Wheel building and publishing / Build wheel on ubuntu-latest (push) Has been cancelled
tests / tests (macos-14, 3.10) (push) Has been cancelled
tests / tests (macos-14, 3.14) (push) Has been cancelled
tests / tests (macos-15-intel, 3.10) (push) Has been cancelled
tests / tests (macos-15-intel, 3.14) (push) Has been cancelled
tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
tests / tests (ubuntu-latest, 3.14) (push) Has been cancelled
tests / tests (windows-latest, 3.10) (push) Has been cancelled
tests / tests (windows-latest, 3.14) (push) Has been cancelled
Run type checking / typecheck (3.10) (push) Has been cancelled
Run type checking / typecheck (3.14) (push) Has been cancelled
Wheel building and publishing / upload_pypi (push) Has been cancelled
Some checks failed
benchmarks / benchmarks (macos-14, 3.12) (push) Has been cancelled
benchmarks / benchmarks (macos-15-intel, 3.12) (push) Has been cancelled
benchmarks / benchmarks (ubuntu-latest, 3.12) (push) Has been cancelled
benchmarks / benchmarks (windows-latest, 3.12) (push) Has been cancelled
Upload coverage reports to Codecov / run (push) Has been cancelled
pylint / lint (3.10) (push) Has been cancelled
Wheel building and publishing / Build wheel on ubuntu-latest (push) Has been cancelled
tests / tests (macos-14, 3.10) (push) Has been cancelled
tests / tests (macos-14, 3.14) (push) Has been cancelled
tests / tests (macos-15-intel, 3.10) (push) Has been cancelled
tests / tests (macos-15-intel, 3.14) (push) Has been cancelled
tests / tests (ubuntu-latest, 3.10) (push) Has been cancelled
tests / tests (ubuntu-latest, 3.14) (push) Has been cancelled
tests / tests (windows-latest, 3.10) (push) Has been cancelled
tests / tests (windows-latest, 3.14) (push) Has been cancelled
Run type checking / typecheck (3.10) (push) Has been cancelled
Run type checking / typecheck (3.14) (push) Has been cancelled
Wheel building and publishing / upload_pypi (push) Has been cancelled
Add type annotations to Builder.__enter__()
This commit is contained in:
commit
8c06e75004
1 changed files with 8 additions and 6 deletions
|
|
@ -219,13 +219,13 @@ class Builder(ABC, Generic[ShapeT]):
|
|||
self.mode = mode
|
||||
planes = WorkplaneList._convert_to_planes(workplanes)
|
||||
self.workplanes = planes if planes else [Plane.XY]
|
||||
self._reset_tok = None
|
||||
self._reset_tok: contextvars.Token[Builder] | None = None
|
||||
current_frame = inspect.currentframe()
|
||||
assert current_frame is not None
|
||||
assert current_frame.f_back is not None
|
||||
self._python_frame = current_frame.f_back.f_back
|
||||
self.parent_frame = None
|
||||
self.builder_parent = None
|
||||
self.builder_parent: Builder | None = None
|
||||
self.lasts: dict = {Vertex: [], Edge: [], Face: [], Solid: []}
|
||||
self.workplanes_context = None
|
||||
self.exit_workplanes: list[Plane] = []
|
||||
|
|
@ -256,21 +256,23 @@ class Builder(ABC, Generic[ShapeT]):
|
|||
before_list = [] if self.obj_before is None else [self.obj_before]
|
||||
return new_edges(*(before_list + self.to_combine), combined=self._obj)
|
||||
|
||||
def __enter__(self):
|
||||
def __enter__(self) -> Self:
|
||||
"""Upon entering record the parent and a token to restore contextvars"""
|
||||
|
||||
# Only set parents from the same scope. Note inspect.currentframe() is supported
|
||||
# by CPython in Linux, Window & MacOS but may not be supported in other python
|
||||
# implementations. Support outside of these OS's is outside the scope of this
|
||||
# project.
|
||||
builder_context: Builder | None = Builder._get_context()
|
||||
current_frame = inspect.currentframe()
|
||||
same_scope = (
|
||||
Builder._get_context()._python_frame == inspect.currentframe().f_back
|
||||
if Builder._get_context()
|
||||
builder_context._python_frame == current_frame.f_back
|
||||
if builder_context and current_frame
|
||||
else False
|
||||
)
|
||||
|
||||
if same_scope:
|
||||
self.builder_parent = Builder._get_context()
|
||||
self.builder_parent = builder_context
|
||||
else:
|
||||
self.builder_parent = None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue