Skip to content
Prev Previous commit
Next Next commit
Use getattr to avoid #type:ignore
  • Loading branch information
nicoddemus committed Apr 2, 2021
commit 72d9ef05db231dae98057b235ca70aa4a3b653de
9 changes: 5 additions & 4 deletions testing/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ class Data:
)

module = import_path(fn, mode="importlib", root=tmp_path)
Data: Any = module.Data # type: ignore[attr-defined]
Data: Any = getattr(module, "Data")
data = Data(value="foo")
assert data.value == "foo"
assert data.__module__ == "src.tests.test_dataclass"
Expand All @@ -491,7 +491,8 @@ def round_trip():
)

module = import_path(fn, mode="importlib", root=tmp_path)
action: Any = module.round_trip() # type: ignore[attr-defined]
round_trip = getattr(module, "round_trip")
action = round_trip()
assert action() == 42


Expand Down Expand Up @@ -537,10 +538,10 @@ def round_trip(obj):
return pickle.loads(s)

module = import_path(fn1, mode="importlib", root=tmp_path)
Data1 = module.Data # type: ignore[attr-defined]
Data1 = getattr(module, "Data")

module = import_path(fn2, mode="importlib", root=tmp_path)
Data2 = module.Data # type: ignore[attr-defined]
Data2 = getattr(module, "Data")

assert round_trip(Data1(20)) == Data1(20)
assert round_trip(Data2("hello")) == Data2("hello")
Expand Down