Skip to content

Commit

Permalink
improve type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
mozman committed Jan 2, 2024
1 parent 9210f87 commit ef13be0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/ezdxf/acc/vector.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# distutils: language = c++
# Copyright (c) 2020-2023, Manfred Moitzi
# License: MIT License
from typing import Iterable, List, Sequence, TYPE_CHECKING, Tuple
from typing import Iterable, List, Sequence, TYPE_CHECKING, Tuple, Iterator
from libc.math cimport fabs, sin, cos, M_PI, hypot, atan2, acos, sqrt, fmod
import random

Expand Down Expand Up @@ -113,7 +113,7 @@ cdef class Vec2:
return tuple(Vec2.generate(items))

@staticmethod
def generate(items: Iterable[UVec]) -> Iterable[Vec2]:
def generate(items: Iterable[UVec]) -> Iterator[Vec2]:
return (Vec2(item) for item in items)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion src/ezdxf/math/_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def tuple(cls, items: Iterable[UVec]) -> Sequence[Vec2]:
return tuple(cls.generate(items))

@classmethod
def generate(cls, items: Iterable[UVec]) -> Iterable[Vec2]:
def generate(cls, items: Iterable[UVec]) -> Iterator[Vec2]:
return (cls(item) for item in items)

@classmethod
Expand Down
13 changes: 9 additions & 4 deletions src/ezdxf/npshapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import abc

import numpy as np
import numpy.typing as npt

from ezdxf.math import (
Matrix44,
Vec2,
Expand Down Expand Up @@ -68,7 +70,7 @@ class NumpyShape2d(abc.ABC):
without sacrificing basic functions like transformation and bounding box calculation.
"""

_vertices: np.ndarray = EMPTY_SHAPE
_vertices: npt.NDArray[VertexNumpyType] = EMPTY_SHAPE

def extents(self) -> tuple[Vec2, Vec2]:
"""Returns the extents of the bounding box as tuple (extmin, extmax)."""
Expand All @@ -77,12 +79,12 @@ def extents(self) -> tuple[Vec2, Vec2]:
return Vec2(v.min(0)), Vec2(v.max(0))
else:
raise EmptyShapeError("empty shape has no extends")

@abc.abstractmethod
def clone(self) -> Self:
...

def np_vertices(self) -> np.ndarray:
def np_vertices(self) -> npt.NDArray[VertexNumpyType]:
return self._vertices

def transform_inplace(self, m: Matrix44) -> None:
Expand Down Expand Up @@ -115,6 +117,8 @@ def clone(self) -> Self:
clone._vertices = self._vertices.copy()
return clone

__copy__ = clone

def __len__(self) -> int:
return len(self._vertices)

Expand All @@ -137,6 +141,8 @@ class NumpyPath2d(NumpyShape2d):
"""

_commands: npt.NDArray[CommandNumpyType]

def __init__(self, path: Optional[Path]) -> None:
if path is None:
self._vertices = EMPTY_SHAPE
Expand Down Expand Up @@ -199,7 +205,6 @@ def commands(self) -> Iterator[PathElement]:
yield MoveTo(vertices[index])
index += 1


def to_path(self) -> Path:
"""Returns a new :class:`ezdxf.path.Path` instance."""
vertices = [Vec3(v) for v in self._vertices]
Expand Down

0 comments on commit ef13be0

Please sign in to comment.