Skip to content

Commit b274c6d

Browse files
authored
Merge pull request #153 from pebenito/fix-unused-ignore
various: Fix issues from new mypy.
2 parents dacb7e1 + eb888c9 commit b274c6d

5 files changed

Lines changed: 30 additions & 31 deletions

File tree

sesearch

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ try:
175175
terq.perms = args.perms.split(",")
176176

177177
if args.xperms:
178-
# https://github.com/python/mypy/issues/220
179-
terq.xperms = setools.xperm_str_to_tuple_ranges(args.xperms) # type: ignore
178+
terq.xperms = setools.xperm_str_to_tuple_ranges(args.xperms)
180179

181180
if args.boolean:
182181
if args.boolean_regex:

setools/ibpkeyconquery.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ def pkeys(self) -> policyrep.IbpkeyconRange | None:
6363
return self._pkeys
6464

6565
@pkeys.setter
66-
def pkeys(self, value: tuple[int, int] | None) -> None:
67-
if value:
68-
self._pkeys = policyrep.IbpkeyconRange(*value)
66+
def pkeys(self, value: policyrep.IbpkeyconRange | tuple[int, int] | None) -> None:
67+
if isinstance(value, policyrep.IbpkeyconRange):
68+
self._pkeys = value
6969
else:
70-
self._pkeys = None
70+
self._pkeys = policyrep.IbpkeyconRange(*value) if value else None
7171

7272
@property
7373
def subnet_prefix(self) -> IPv6Address | None:

setools/portconquery.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ def ports(self) -> policyrep.PortconRange | None:
6868
return self._ports
6969

7070
@ports.setter
71-
def ports(self, value: tuple[int, int] | None) -> None:
72-
if value:
73-
self._ports = policyrep.PortconRange(*value)
71+
def ports(self, value: policyrep.PortconRange | tuple[int, int] | None) -> None:
72+
if isinstance(value, policyrep.PortconRange):
73+
self._ports = value
7474
else:
75-
self._ports = None
75+
self._ports = policyrep.PortconRange(*value) if value else None
7676

7777
@property
7878
def protocol(self) -> policyrep.PortconProtocol | None:

tests/library/test_dta.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ def test_exclude_domain(self, analysis: setools.DomainTransitionAnalysis) -> Non
401401
# removed after removing invalid domain transitions
402402

403403
analysis.reverse = False
404-
analysis.exclude = ["trans1"] # type: ignore[list-item]
404+
analysis.exclude = ["trans1"]
405405
analysis._build_subgraph()
406406

407407
start = analysis.policy.lookup_type("start")
@@ -424,7 +424,7 @@ def test_exclude_entryoint_with_2entrypoints(
424424
# removed after removing invalid domain transitions
425425

426426
analysis.reverse = False
427-
analysis.exclude = ["trans3_exec1"] # type: ignore[list-item]
427+
analysis.exclude = ["trans3_exec1"]
428428
analysis._build_subgraph()
429429

430430
start = analysis.policy.lookup_type("start")
@@ -450,7 +450,7 @@ def test_exclude_entryoint_with_dyntrans(
450450
# removed after removing invalid domain transitions
451451

452452
analysis.reverse = False
453-
analysis.exclude = ["bothtrans200_exec"] # type: ignore[list-item]
453+
analysis.exclude = ["bothtrans200_exec"]
454454
analysis._build_subgraph()
455455

456456
start = analysis.policy.lookup_type("start")
@@ -476,7 +476,7 @@ def test_exclude_entryoint_delete_transition(
476476
# removed after removing invalid domain transitions
477477

478478
analysis.reverse = False
479-
analysis.exclude = ["trans2_exec"] # type: ignore[list-item]
479+
analysis.exclude = ["trans2_exec"]
480480
analysis._build_subgraph()
481481

482482
start = analysis.policy.lookup_type("start")
@@ -759,7 +759,7 @@ def test_set_exclude_invalid_type(self, analysis: setools.DomainTransitionAnalys
759759
analysis.reverse = False
760760
analysis.exclude = []
761761
with pytest.raises(setools.exception.InvalidType):
762-
analysis.exclude = ["trans1", "invalid_type"] # type: ignore[list-item]
762+
analysis.exclude = ["trans1", "invalid_type"]
763763

764764
def test_all_paths_invalid_source(self, analysis: setools.DomainTransitionAnalysis) -> None:
765765
"""DTA: all paths with invalid source type."""
@@ -788,7 +788,7 @@ def test_all_paths_invalid_maxlen(self, analysis: setools.DomainTransitionAnalys
788788
def test_all_paths_source_excluded(self, analysis: setools.DomainTransitionAnalysis) -> None:
789789
"""DTA: all paths with excluded source type."""
790790
analysis.reverse = False
791-
analysis.exclude = ["trans1"] # type: ignore[list-item]
791+
analysis.exclude = ["trans1"]
792792
analysis.source = "trans1"
793793
analysis.target = "trans2"
794794
analysis.mode = setools.DomainTransitionAnalysis.Mode.AllPaths
@@ -798,7 +798,7 @@ def test_all_paths_source_excluded(self, analysis: setools.DomainTransitionAnaly
798798
def test_all_paths_target_excluded(self, analysis: setools.DomainTransitionAnalysis) -> None:
799799
"""DTA: all paths with excluded target type."""
800800
analysis.reverse = False
801-
analysis.exclude = ["trans2"] # type: ignore[list-item]
801+
analysis.exclude = ["trans2"]
802802
analysis.source = "trans1"
803803
analysis.target = "trans2"
804804
analysis.mode = setools.DomainTransitionAnalysis.Mode.AllPaths
@@ -820,7 +820,7 @@ def test_all_paths_target_disconnected(
820820
self, analysis: setools.DomainTransitionAnalysis) -> None:
821821
"""DTA: all paths with disconnected target type."""
822822
analysis.reverse = False
823-
analysis.exclude = ["trans3"] # type: ignore[list-item]
823+
analysis.exclude = ["trans3"]
824824
analysis.source = "trans2"
825825
analysis.target = "trans5"
826826
analysis.mode = setools.DomainTransitionAnalysis.Mode.AllPaths
@@ -831,7 +831,7 @@ def test_shortest_path_target_disconnected(
831831
self, analysis: setools.DomainTransitionAnalysis) -> None:
832832
"""DTA: shortest path with disconnected target type."""
833833
analysis.reverse = False
834-
analysis.exclude = ["trans3"] # type: ignore[list-item]
834+
analysis.exclude = ["trans3"]
835835
analysis.source = "trans2"
836836
analysis.target = "trans5"
837837
analysis.mode = setools.DomainTransitionAnalysis.Mode.ShortestPaths
@@ -842,7 +842,7 @@ def test_all_shortest_paths_source_excluded(
842842
self, analysis: setools.DomainTransitionAnalysis) -> None:
843843
"""DTA: all shortest paths with excluded source type."""
844844
analysis.reverse = False
845-
analysis.exclude = ["trans1"] # type: ignore[list-item]
845+
analysis.exclude = ["trans1"]
846846
analysis.source = "trans1"
847847
analysis.target = "trans2"
848848
analysis.mode = setools.DomainTransitionAnalysis.Mode.ShortestPaths
@@ -853,7 +853,7 @@ def test_all_shortest_paths_target_excluded(
853853
self, analysis: setools.DomainTransitionAnalysis) -> None:
854854
"""DTA: all shortest paths with excluded target type."""
855855
analysis.reverse = False
856-
analysis.exclude = ["trans2"] # type: ignore[list-item]
856+
analysis.exclude = ["trans2"]
857857
analysis.source = "trans1"
858858
analysis.target = "trans2"
859859
analysis.mode = setools.DomainTransitionAnalysis.Mode.ShortestPaths
@@ -875,7 +875,7 @@ def test_all_shortest_paths_target_disconnected(
875875
self, analysis: setools.DomainTransitionAnalysis) -> None:
876876
"""DTA: all shortest paths with disconnected target type."""
877877
analysis.reverse = False
878-
analysis.exclude = ["trans3"] # type: ignore[list-item]
878+
analysis.exclude = ["trans3"]
879879
analysis.source = "trans2"
880880
analysis.target = "trans5"
881881
analysis.mode = setools.DomainTransitionAnalysis.Mode.ShortestPaths
@@ -885,7 +885,7 @@ def test_all_shortest_paths_target_disconnected(
885885
def test_transitions_source_excluded(self, analysis: setools.DomainTransitionAnalysis) -> None:
886886
"""DTA: transitions with excluded source type."""
887887
analysis.reverse = False
888-
analysis.exclude = ["trans1"] # type: ignore[list-item]
888+
analysis.exclude = ["trans1"]
889889
analysis.mode = setools.DomainTransitionAnalysis.Mode.TransitionsOut
890890
analysis.source = "trans1"
891891
paths = list(analysis.results())
@@ -895,7 +895,7 @@ def test_transitions_source_disconnected(
895895
self, analysis: setools.DomainTransitionAnalysis) -> None:
896896
"""DTA: transitions with disconnected source type."""
897897
analysis.reverse = False
898-
analysis.exclude = ["trans3"] # type: ignore[list-item]
898+
analysis.exclude = ["trans3"]
899899
analysis.source = "trans5"
900900
analysis.mode = setools.DomainTransitionAnalysis.Mode.TransitionsOut
901901
paths = list(analysis.results())

tests/library/test_infoflow.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def test_infoflows_in(self, analysis: setools.InfoFlowAnalysis) -> None:
292292
def test_set_exclude_invalid_type(self, analysis: setools.InfoFlowAnalysis) -> None:
293293
"""Information flow analysis: set invalid excluded type."""
294294
with pytest.raises(setools.exception.InvalidType):
295-
analysis.exclude = ["node1", "invalid_type"] # type: ignore[list-item]
295+
analysis.exclude = ["node1", "invalid_type"]
296296

297297
def test_set_small_min_weight(self, analysis: setools.InfoFlowAnalysis) -> None:
298298
"""Information flow analysis: set too small weight."""
@@ -332,7 +332,7 @@ def test_all_paths_invalid_maxlen(self, analysis: setools.InfoFlowAnalysis) -> N
332332

333333
def test_all_paths_source_excluded(self, analysis: setools.InfoFlowAnalysis) -> None:
334334
"""Information flow analysis: all paths with excluded source type."""
335-
analysis.exclude = ["node1"] # type: ignore[list-item]
335+
analysis.exclude = ["node1"]
336336
analysis.min_weight = 1
337337
analysis.mode = setools.InfoFlowAnalysis.Mode.AllPaths
338338
analysis.source = "node1"
@@ -342,7 +342,7 @@ def test_all_paths_source_excluded(self, analysis: setools.InfoFlowAnalysis) ->
342342

343343
def test_all_paths_target_excluded(self, analysis: setools.InfoFlowAnalysis) -> None:
344344
"""Information flow analysis: all paths with excluded target type."""
345-
analysis.exclude = ["node2"] # type: ignore[list-item]
345+
analysis.exclude = ["node2"]
346346
analysis.min_weight = 1
347347
analysis.mode = setools.InfoFlowAnalysis.Mode.AllPaths
348348
analysis.source = "node1"
@@ -372,7 +372,7 @@ def test_all_paths_target_disconnected(self, analysis: setools.InfoFlowAnalysis)
372372

373373
def test_all_shortest_paths_source_excluded(self, analysis: setools.InfoFlowAnalysis) -> None:
374374
"""Information flow analysis: all shortest paths with excluded source type."""
375-
analysis.exclude = ["node1"] # type: ignore[list-item]
375+
analysis.exclude = ["node1"]
376376
analysis.min_weight = 1
377377
analysis.mode = setools.InfoFlowAnalysis.Mode.ShortestPaths
378378
analysis.source = "node1"
@@ -382,7 +382,7 @@ def test_all_shortest_paths_source_excluded(self, analysis: setools.InfoFlowAnal
382382

383383
def test_all_shortest_paths_target_excluded(self, analysis: setools.InfoFlowAnalysis) -> None:
384384
"""Information flow analysis: all shortest paths with excluded target type."""
385-
analysis.exclude = ["node2"] # type: ignore[list-item]
385+
analysis.exclude = ["node2"]
386386
analysis.min_weight = 1
387387
analysis.mode = setools.InfoFlowAnalysis.Mode.ShortestPaths
388388
analysis.source = "node1"
@@ -414,7 +414,7 @@ def test_all_shortest_paths_target_disconnected(
414414

415415
def test_infoflows_source_excluded(self, analysis: setools.InfoFlowAnalysis) -> None:
416416
"""Information flow analysis: infoflows with excluded source type."""
417-
analysis.exclude = ["node1"] # type: ignore[list-item]
417+
analysis.exclude = ["node1"]
418418
analysis.min_weight = 1
419419
analysis.mode = setools.InfoFlowAnalysis.Mode.FlowsOut
420420
analysis.source = "node1"
@@ -423,7 +423,7 @@ def test_infoflows_source_excluded(self, analysis: setools.InfoFlowAnalysis) ->
423423

424424
def test_infoflows_source_disconnected(self, analysis: setools.InfoFlowAnalysis) -> None:
425425
"""Information flow analysis: infoflows with disconnected source type."""
426-
analysis.exclude = ["disconnected2"] # type: ignore[list-item]
426+
analysis.exclude = ["disconnected2"]
427427
analysis.min_weight = 1
428428
analysis.mode = setools.InfoFlowAnalysis.Mode.FlowsOut
429429
analysis.source = "disconnected1"

0 commit comments

Comments
 (0)