Skip to content

Commit 678719c

Browse files
Fix MyPy issues
1 parent db73371 commit 678719c

7 files changed

Lines changed: 20 additions & 17 deletions

File tree

pynetdicom/ae.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def add_supported_context(
412412
else:
413413
context = PresentationContext()
414414
context.abstract_syntax = abstract_syntax
415-
context.transfer_syntax = transfer_syntax # type: ignore
415+
context.transfer_syntax = transfer_syntax
416416
context.scu_role = None or scu_role
417417
context.scp_role = None or scp_role
418418

pynetdicom/association.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ def send_c_store(
18451845
if not _config.STORE_SEND_CHUNKED_DATASET:
18461846
dataset = dcmread(os.fspath(fpath))
18471847
else:
1848-
dataset = None # type: ignore[assignment]
1848+
dataset = None
18491849
allow_conversion = False
18501850
file_meta, offset = split_dataset(fpath)
18511851
req._dataset_path = (fpath, offset)

pynetdicom/dimse_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def decode_msg(self, primitive: P_DATA, assoc: "Association | None" = None) -> b
474474
sop_class = cast(UID, cs.AffectedSOPClassUID)
475475
sop_instance = cast(UID, cs.AffectedSOPInstanceUID)
476476
write_file_meta_info(
477-
self._data_set_file, # type: ignore
477+
self._data_set_file,
478478
create_file_meta(
479479
sop_class_uid=sop_class,
480480
sop_instance_uid=sop_instance,

pynetdicom/dsutils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def encode(
155155
fp.close()
156156
return None
157157

158-
bytestring: bytes = fp.parent.getvalue() # type: ignore
158+
bytestring: bytes = fp.parent.getvalue()
159159
fp.close()
160160

161161
if deflated:
@@ -181,7 +181,7 @@ def encode_file_meta(file_meta: FileMetaDataset) -> bytes:
181181
buffer.is_little_endian = True
182182
buffer.is_implicit_VR = False
183183
write_file_meta_info(buffer, file_meta)
184-
return buffer.getvalue()
184+
return buffer.getvalue() # type: ignore[no-any-return] # FIXME
185185

186186

187187
def pretty_dataset(ds: Dataset, indent: int = 0, indent_char: str = " ") -> list[str]:
@@ -288,7 +288,7 @@ def split_dataset(path: Path) -> tuple[Dataset, int]:
288288

289289
def _not_group_0002(tag: BaseTag, VR: str | None, length: int) -> bool:
290290
"""Return True if the tag is not in group 0x0002, False otherwise."""
291-
return tag.group != 2
291+
return tag.group != 2 # type: ignore[no-any-return] # FIXME
292292

293293
with open(path, "rb") as fp:
294294
read_preamble(fp, False)

pynetdicom/pdu_items.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,7 @@ def from_primitive(self, primitive: "SOPClassCommonExtendedNegotiation") -> None
26372637
self.sop_class_uid = primitive.sop_class_uid
26382638
self.service_class_uid = primitive.service_class_uid
26392639
self.related_general_sop_class_identification = (
2640-
primitive.related_general_sop_class_identification # type: ignore[assignment]
2640+
primitive.related_general_sop_class_identification
26412641
)
26422642

26432643
def to_primitive(self) -> "SOPClassCommonExtendedNegotiation":
@@ -2655,7 +2655,7 @@ def to_primitive(self) -> "SOPClassCommonExtendedNegotiation":
26552655
primitive.sop_class_uid = self.sop_class_uid
26562656
primitive.service_class_uid = self.service_class_uid
26572657
primitive.related_general_sop_class_identification = (
2658-
self.related_general_sop_class_identification # type: ignore[assignment]
2658+
self.related_general_sop_class_identification
26592659
)
26602660

26612661
return primitive
@@ -2732,7 +2732,7 @@ def _encoders(self) -> Any:
27322732
]
27332733

27342734
@staticmethod
2735-
def _generate_items(bytestream: bytes) -> Iterator[UID]: # type: ignore
2735+
def _generate_items(bytestream: bytes) -> Iterator[UID]:
27362736
"""Yield Related General SOP Class UIDs from `bytestream`.
27372737
27382738
Parameters
@@ -2905,7 +2905,7 @@ def __str__(self) -> str:
29052905

29062906
return "\n".join(s)
29072907

2908-
def _wrap_generate_items(self, b: bytes) -> list[UID]: # type: ignore
2908+
def _wrap_generate_items(self, b: bytes) -> list[UID]:
29092909
"""Return a list of UID items generated from `bytestream`."""
29102910
return list(self._generate_items(b))
29112911

pynetdicom/presentation.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ def add_transfer_syntax(self, syntax: None | str | bytes | UID) -> None:
250250
if syntax is None:
251251
return
252252

253-
if isinstance(syntax, str): # includes UID
253+
if isinstance(syntax, UID):
254+
pass
255+
elif isinstance(syntax, str):
254256
syntax = UID(syntax)
255257
elif isinstance(syntax, bytes):
256258
syntax = UID(syntax.decode("ascii"))
@@ -264,15 +266,16 @@ def add_transfer_syntax(self, syntax: None | str | bytes | UID) -> None:
264266

265267
# If the transfer syntax is rejected we may receive an empty str
266268
if syntax not in self._transfer_syntax and syntax != "":
267-
if not syntax.is_valid:
269+
if not syntax.is_valid: # type: ignore[union-attr] # FIXME
268270
LOGGER.warning(
269-
f"A non-conformant UID has been added to 'transfer_syntax': '{syntax}'"
271+
"A non-conformant UID has been added to 'transfer_syntax': "
272+
f"'{syntax}'" # type: ignore[str-bytes-safe] # FIXME
270273
)
271274

272-
if not syntax.is_private and not syntax.is_transfer_syntax:
275+
if not syntax.is_private and not syntax.is_transfer_syntax: # type: ignore[union-attr] # FIXME
273276
LOGGER.warning(
274277
"A UID has been added to 'transfer_syntax' that is not a known "
275-
f"public transfer syntax: '{syntax}'"
278+
f"public transfer syntax: '{syntax}'" # type: ignore[str-bytes-safe] # FIXME
276279
)
277280

278281
self._transfer_syntax.append(syntax)
@@ -365,7 +368,7 @@ def __ne__(self, other: object) -> bool:
365368

366369
def __repr__(self) -> str:
367370
"""Representation of the Presentation Context."""
368-
return cast(UID, self.abstract_syntax).name
371+
return cast(UID, self.abstract_syntax).name # type: ignore[no-any-return] # FIXME
369372

370373
@property
371374
def scp_role(self) -> None | bool:

pynetdicom/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,6 @@ def validate_uid(uid: UID) -> bool:
335335
``True`` if the value is considered valid, ``False`` otherwise.
336336
"""
337337
if _config.ENFORCE_UID_CONFORMANCE:
338-
return uid.is_valid
338+
return uid.is_valid # type: ignore[no-any-return] # FIXME
339339

340340
return 0 < len(uid) < 65

0 commit comments

Comments
 (0)