Skip to content

Commit 95ee679

Browse files
committed
Fix preexisting type errors exposed by mypy
1 parent 8e042a5 commit 95ee679

48 files changed

Lines changed: 170 additions & 144 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ezdxf/acc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
if USE_C_EXT:
3333
try:
34-
from ezdxf.acc import vector
34+
from ezdxf.acc import vector # type: ignore[attr-defined]
3535
except ImportError:
3636
USE_C_EXT = False
3737

src/ezdxf/addons/dimlines.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ def _get_section_points(self, section: int) -> tuple[Vec3, Vec3]:
312312
"""
313313
Get start and end point on the dimension line of dimension section.
314314
"""
315-
return self._get_dimline_point(section), self._get_dimline_point(
315+
return Vec3(self._get_dimline_point(section)), Vec3(self._get_dimline_point(
316316
section + 1
317-
)
317+
))
318318

319319
def _get_dimline_bounds(self) -> tuple[Vec3, Vec3]:
320320
"""
321321
Get the first and the last point of dimension line.
322322
"""
323-
return self._get_dimline_point(0), self._get_dimline_point(-1)
323+
return Vec3(self._get_dimline_point(0)), Vec3(self._get_dimline_point(-1))
324324

325325
@property
326326
def section_count(self) -> int:
@@ -357,7 +357,7 @@ def _build_vectors(self) -> None:
357357
@staticmethod
358358
def _get_point_on_dimline(point: UVec, dimray: ConstructionRay) -> Vec3:
359359
"""get the measure target point projection on the dimension line"""
360-
return dimray.intersect(dimray.orthogonal(point))
360+
return Vec3(dimray.intersect(dimray.orthogonal(point)))
361361

362362
def _draw_dimline(self, layout: "GenericLayoutType") -> None:
363363
"""build dimension line entity"""
@@ -640,9 +640,9 @@ def __init__(
640640
def _setup(self) -> None:
641641
super()._setup()
642642
if self.arc3points:
643-
self.center = center_of_3points_arc(
643+
self.center = Vec3(center_of_3points_arc(
644644
self.center, self.start, self.end
645-
)
645+
))
646646

647647
def _get_extline_start(self, vector: Vec3) -> Vec3:
648648
return self.center + (

src/ezdxf/addons/drawing/debug_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ def draw_rect(points: list[Vec3], color: Color, out: BackendInterface):
1212

1313
props = BackendProperties(color=color)
1414
for a, b in zip(points, points[1:]):
15-
out.draw_line(a, b, props)
15+
out.draw_line(a, b, props) # type: ignore[arg-type]

src/ezdxf/addons/drawing/dxf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def draw_filled_polygon(
160160
self, points: BkPoints2d, properties: BackendProperties
161161
) -> None:
162162
hatch = self.layout.add_hatch(dxfattribs=self.resolve_properties(properties))
163-
hatch.paths.add_polyline_path(points.vertices(), is_closed=True)
163+
hatch.paths.add_polyline_path(points.vertices(), is_closed=True) # type: ignore[arg-type]
164164
self.set_solid_fill(hatch, properties)
165165

166166
def draw_image(self, image_data: ImageData, properties: BackendProperties) -> None:

src/ezdxf/addons/drawing/frontend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,10 @@ def timeout() -> bool:
575575
for s, e in line_pattern.render(line.start, line.end):
576576
if ocs.transform:
577577
s, e = (
578-
ocs.to_wcs((s.x, s.y, elevation)),
579-
ocs.to_wcs((e.x, e.y, elevation)),
578+
ocs.to_wcs((s.x, s.y, elevation)).vec2,
579+
ocs.to_wcs((e.x, e.y, elevation)).vec2,
580580
)
581-
lines.append((s, e))
581+
lines.append((s, e)) # type: ignore[arg-type]
582582
self.pipeline.draw_solid_lines(lines, properties)
583583

584584
def draw_hatch_entity(

src/ezdxf/addons/drawing/mtext_complex.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def corner_vertices(
2525
bottom: float,
2626
right: float,
2727
top: float,
28-
m: Matrix44 = None,
28+
m: Matrix44 | None = None,
2929
) -> Iterable[Vec3]:
3030
corners = [ # closed polygon: fist vertex == last vertex
3131
(left, top),
@@ -70,7 +70,7 @@ def render(
7070
bottom: float,
7171
right: float,
7272
top: float,
73-
m: Matrix44 = None,
73+
m: Matrix44 | None = None,
7474
) -> None:
7575
self._render_outline(list(corner_vertices(left, bottom, right, top, m)))
7676

@@ -83,7 +83,7 @@ def _render_outline(self, vertices: list[Vec3]) -> None:
8383
prev = vertex
8484

8585
def line(
86-
self, x1: float, y1: float, x2: float, y2: float, m: Matrix44 = None
86+
self, x1: float, y1: float, x2: float, y2: float, m: Matrix44 | None = None
8787
) -> None:
8888
points = [(x1, y1), (x2, y2)]
8989
if m is not None:
@@ -113,7 +113,7 @@ def render(
113113
bottom: float,
114114
right: float,
115115
top: float,
116-
m: Matrix44 = None,
116+
m: Matrix44 | None = None,
117117
) -> None:
118118
# Important: this is not a clipping box, it is possible to
119119
# render anything outside of the given borders!
@@ -153,7 +153,7 @@ def render(
153153
bottom: float,
154154
right: float,
155155
top: float,
156-
m: Matrix44 = None,
156+
m: Matrix44 | None = None,
157157
):
158158
"""Create/render the text content"""
159159
sx = 1.0

src/ezdxf/addons/drawing/pipeline.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,10 @@ def set_config(self, config: Configuration) -> None:
429429

430430
def draw_point(self, pos: Vec2, properties: Properties) -> None:
431431
if self.clipping_portal.is_active:
432-
pos = self.clipping_portal.clip_point(pos)
433-
if pos is None:
432+
clipped = self.clipping_portal.clip_point(pos)
433+
if clipped is None:
434434
return
435+
pos = clipped
435436
self.next_stage.draw_point(pos, properties)
436437

437438
def draw_line(self, start: Vec2, end: Vec2, properties: Properties):
@@ -613,7 +614,7 @@ def draw_line(self, start: Vec2, end: Vec2, properties: Properties):
613614

614615
renderer = linetypes.LineTypeRenderer(self.pattern(properties))
615616
next_stage.draw_solid_lines(
616-
[(s, e) for s, e in renderer.line_segment(s, e)],
617+
[(s, e) for s, e in renderer.line_segment(s, e)], # type: ignore[misc]
617618
properties,
618619
)
619620

src/ezdxf/addons/mtxpl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def render(
3232
bottom: float,
3333
right: float,
3434
top: float,
35-
m: Matrix44 = None,
35+
m: Matrix44 | None = None,
3636
) -> None:
3737
pline = self.layout.add_lwpolyline(
3838
[(left, top), (right, top), (right, bottom), (left, bottom)],
@@ -43,7 +43,7 @@ def render(
4343
pline.transform(m)
4444

4545
def line(
46-
self, x1: float, y1: float, x2: float, y2: float, m: Matrix44 = None
46+
self, x1: float, y1: float, x2: float, y2: float, m: Matrix44 | None = None
4747
) -> None:
4848
line = self.layout.add_line((x1, y1), (x2, y2), dxfattribs=self.line_attribs)
4949
if m:

src/ezdxf/addons/text2path.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def make_path_from_str(
3535
size: float = 1.0,
3636
align=TextEntityAlignment.LEFT,
3737
length: float = 0,
38-
m: Matrix44 = None,
38+
m: Matrix44 | None = None,
3939
) -> Path:
4040
"""Convert a single line string `s` into a :term:`Multi-Path` object.
4141
The text `size` is the height of the uppercase letter "X" (cap height).
@@ -74,7 +74,7 @@ def make_paths_from_str(
7474
size: float = 1.0,
7575
align=TextEntityAlignment.LEFT,
7676
length: float = 0,
77-
m: Matrix44 = None,
77+
m: Matrix44 | None = None,
7878
) -> list[Path]:
7979
"""Convert a single line string `s` into a list of
8080
:class:`~ezdxf.path.Path` objects. All paths are returned as a list of
@@ -174,7 +174,7 @@ def make_hatches_from_str(
174174
align=TextEntityAlignment.LEFT,
175175
length: float = 0,
176176
dxfattribs=None,
177-
m: Matrix44 = None,
177+
m: Matrix44 | None = None,
178178
) -> list[Hatch]:
179179
"""Convert a single line string `s` into a list of virtual
180180
:class:`~ezdxf.entities.Hatch` entities.

src/ezdxf/edgeminer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def unique_vertices(self) -> set[Vec3]:
352352
e.g. if the vertices a, b are close together, you don't know if you get a or b,
353353
but it's guaranteed that you only get one of them
354354
"""
355-
return filter_close_vertices(self._search_index.rtree, gap_tol=self.gap_tol)
355+
return filter_close_vertices(self._search_index.rtree, gap_tol=self.gap_tol) # type: ignore[arg-type]
356356

357357
def edges_linked_to(self, vertex: UVec, radius: float = -1) -> Sequence[Edge]:
358358
"""Returns all edges linked to `vertex` in range of `radius`.
@@ -373,14 +373,14 @@ def find_nearest_edge(self, vertex: UVec) -> Edge | None:
373373
The distance is measured to the connection line from start to end of the edge.
374374
This is not correct for edges that represent arcs or splines.
375375
"""
376+
vertex = Vec3(vertex)
376377

377378
def distance(edge: Edge) -> float:
378379
try:
379380
return distance_point_line_3d(vertex, edge.start, edge.end)
380381
except ZeroDivisionError:
381382
return edge.start.distance(vertex)
382383

383-
vertex = Vec3(vertex)
384384
si = self._search_index
385385
nearest_vertex = si.nearest_vertex(vertex)
386386
edges = self.edges_linked_to(nearest_vertex)
@@ -738,16 +738,16 @@ def __init__(self, edges: Sequence[Edge]) -> None:
738738
self._search_tree = rtree.RTree(vertices)
739739

740740
@property
741-
def rtree(self) -> rtree.RTree[Vec3]:
741+
def rtree(self) -> rtree.RTree[_Vertex]:
742742
return self._search_tree
743743

744744
def vertices_in_sphere(self, center: Vec3, radius: float) -> Sequence[_Vertex]:
745745
"""Returns all vertices located around `center` with a max. distance of `radius`."""
746-
return tuple(self._search_tree.points_in_sphere(center, radius))
746+
return tuple(self._search_tree.points_in_sphere(center, radius)) # type: ignore[arg-type]
747747

748748
def nearest_vertex(self, location: Vec3) -> _Vertex:
749749
"""Returns the nearest vertex to the given location."""
750-
vertex, _ = self._search_tree.nearest_neighbor(location)
750+
vertex, _ = self._search_tree.nearest_neighbor(location) # type: ignore[arg-type]
751751
return vertex
752752

753753

0 commit comments

Comments
 (0)