fix more type issues
This commit is contained in:
parent
557c6c98dc
commit
db9b39dbc0
11 changed files with 54 additions and 34 deletions
|
|
@ -127,7 +127,7 @@ def readfile(
|
|||
filename: Union[str, pathlib.Path],
|
||||
*args,
|
||||
**kwargs,
|
||||
) -> Tuple[Pattern, Dict[str, Any]]:
|
||||
) -> Tuple[Dict[str, Pattern], Dict[str, Any]]:
|
||||
"""
|
||||
Wrapper for `dxf.read()` that takes a filename or path instead of a stream.
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ Notes:
|
|||
* Creation/modification/access times are set to 1900-01-01 for reproducibility.
|
||||
"""
|
||||
from typing import List, Any, Dict, Tuple, Callable, Union, Iterable, Optional
|
||||
from typing import Sequence, BinaryIO, Mapping
|
||||
from typing import Sequence, BinaryIO, Mapping, cast
|
||||
import re
|
||||
import io
|
||||
import mmap
|
||||
|
|
@ -298,7 +298,7 @@ def _gref_to_mref(ref: klamath.library.Reference) -> Ref:
|
|||
repetition = Grid(a_vector=a_vector, b_vector=b_vector,
|
||||
a_count=a_count, b_count=b_count)
|
||||
|
||||
ref = Ref(
|
||||
mref = Ref(
|
||||
target=ref.struct_name.decode('ASCII'),
|
||||
offset=offset,
|
||||
rotation=numpy.deg2rad(ref.angle_deg),
|
||||
|
|
@ -307,7 +307,7 @@ def _gref_to_mref(ref: klamath.library.Reference) -> Ref:
|
|||
annotations=_properties_to_annotations(ref.properties),
|
||||
repetition=repetition,
|
||||
)
|
||||
return ref
|
||||
return mref
|
||||
|
||||
|
||||
def _gpath_to_mpath(gpath: klamath.library.Path, raw_mode: bool) -> Path:
|
||||
|
|
@ -341,7 +341,7 @@ def _boundary_to_polygon(boundary: klamath.library.Boundary, raw_mode: bool) ->
|
|||
|
||||
|
||||
def _mrefs_to_grefs(refs: List[Ref]) -> List[klamath.library.Reference]:
|
||||
refs = []
|
||||
grefs = []
|
||||
for ref in refs:
|
||||
if ref.target is None:
|
||||
continue
|
||||
|
|
@ -370,9 +370,9 @@ def _mrefs_to_grefs(refs: List[Ref]) -> List[klamath.library.Reference]:
|
|||
mag=ref.scale,
|
||||
properties=properties,
|
||||
)
|
||||
refs.append(aref)
|
||||
grefs.append(aref)
|
||||
elif rep is None:
|
||||
ref = klamath.library.Reference(
|
||||
sref = klamath.library.Reference(
|
||||
struct_name=encoded_name,
|
||||
xy=rint_cast([ref.offset]),
|
||||
colrow=None,
|
||||
|
|
@ -381,7 +381,7 @@ def _mrefs_to_grefs(refs: List[Ref]) -> List[klamath.library.Reference]:
|
|||
mag=ref.scale,
|
||||
properties=properties,
|
||||
)
|
||||
refs.append(ref)
|
||||
grefs.append(sref)
|
||||
else:
|
||||
new_srefs = [
|
||||
klamath.library.Reference(
|
||||
|
|
@ -394,8 +394,8 @@ def _mrefs_to_grefs(refs: List[Ref]) -> List[klamath.library.Reference]:
|
|||
properties=properties,
|
||||
)
|
||||
for dd in rep.displacements]
|
||||
refs += new_srefs
|
||||
return refs
|
||||
grefs += new_srefs
|
||||
return grefs
|
||||
|
||||
|
||||
def _properties_to_annotations(properties: Dict[int, bytes]) -> annotations_t:
|
||||
|
|
@ -635,17 +635,17 @@ def load_libraryfile(
|
|||
if is_gzipped(path):
|
||||
if mmap:
|
||||
logger.info('Asked to mmap a gzipped file, reading into memory instead...')
|
||||
base_stream = gzip.open(path, mode='rb')
|
||||
stream = io.BytesIO(base_stream.read())
|
||||
gz_stream = gzip.open(path, mode='rb')
|
||||
stream = io.BytesIO(gz_stream.read()) # type: ignore
|
||||
else:
|
||||
base_stream = gzip.open(path, mode='rb')
|
||||
stream = io.BufferedReader(base_stream)
|
||||
gz_stream = gzip.open(path, mode='rb')
|
||||
stream = io.BufferedReader(gz_stream) # type: ignore
|
||||
else:
|
||||
base_stream = open(path, mode='rb')
|
||||
if mmap:
|
||||
stream = mmap.mmap(base_stream.fileno(), 0, access=mmap.ACCESS_READ)
|
||||
base_stream = open(path, mode='rb', buffering=0)
|
||||
stream = mmap.mmap(base_stream.fileno(), 0, access=mmap.ACCESS_READ) # type: ignore
|
||||
else:
|
||||
stream = io.BufferedReader(base_stream)
|
||||
stream = open(path, mode='rb')
|
||||
return load_library(stream, full_load=full_load)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -484,8 +484,10 @@ def _placement_to_ref(placement: fatrec.Placement, lib: fatamorgana.OasisLayout)
|
|||
assert(not isinstance(placement.repetition, fatamorgana.ReuseRepetition))
|
||||
xy = numpy.array((placement.x, placement.y))
|
||||
mag = placement.magnification if placement.magnification is not None else 1
|
||||
|
||||
pname = placement.get_name()
|
||||
name = pname if isinstance(pname, int) else pname.string
|
||||
name: Union[int, str] = pname if isinstance(pname, int) else pname.string # TODO deal with referenced names
|
||||
|
||||
annotations = properties_to_annotations(placement.properties, lib.propnames, lib.propstrings)
|
||||
if placement.angle is None:
|
||||
rotation = 0
|
||||
|
|
@ -506,7 +508,7 @@ def _placement_to_ref(placement: fatrec.Placement, lib: fatamorgana.OasisLayout)
|
|||
def _refs_to_placements(
|
||||
refs: List[Ref],
|
||||
) -> List[fatrec.Placement]:
|
||||
refs = []
|
||||
placements = []
|
||||
for ref in refs:
|
||||
if ref.target is None:
|
||||
continue
|
||||
|
|
@ -517,7 +519,7 @@ def _refs_to_placements(
|
|||
|
||||
offset = rint_cast(ref.offset + rep_offset)
|
||||
angle = numpy.rad2deg(ref.rotation + extra_angle) % 360
|
||||
ref = fatrec.Placement(
|
||||
placement = fatrec.Placement(
|
||||
name=ref.target,
|
||||
flip=mirror_across_x,
|
||||
angle=angle,
|
||||
|
|
@ -528,8 +530,8 @@ def _refs_to_placements(
|
|||
repetition=frep,
|
||||
)
|
||||
|
||||
refs.append(ref)
|
||||
return refs
|
||||
placements.append(placement)
|
||||
return placements
|
||||
|
||||
|
||||
def _shapes_to_elements(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue