Skip to content

Commit b0aabe4

Browse files
committed
fix mypy 0.930 errors
1 parent cbccc06 commit b0aabe4

File tree

6 files changed

+16
-3
lines changed

6 files changed

+16
-3
lines changed

src/_pytest/config/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,7 @@ def _getconftest_pathlist(
14291429
)
14301430
except KeyError:
14311431
return None
1432+
assert mod.__file__ is not None
14321433
modpath = Path(mod.__file__).parent
14331434
values: List[Path] = []
14341435
for relroot in relroots:
@@ -1574,7 +1575,7 @@ def _strtobool(val: str) -> bool:
15741575
@lru_cache(maxsize=50)
15751576
def parse_warning_filter(
15761577
arg: str, *, escape: bool
1577-
) -> Tuple[str, str, Type[Warning], str, int]:
1578+
) -> Tuple["warnings._ActionKind", str, Type[Warning], str, int]:
15781579
"""Parse a warnings filter string.
15791580
15801581
This is copied from warnings._setoption with the following changes:
@@ -1616,7 +1617,7 @@ def parse_warning_filter(
16161617
parts.append("")
16171618
action_, message, category_, module, lineno_ = (s.strip() for s in parts)
16181619
try:
1619-
action: str = warnings._getaction(action_) # type: ignore[attr-defined]
1620+
action: "warnings._ActionKind" = warnings._getaction(action_) # type: ignore[attr-defined]
16201621
except warnings._OptionError as e:
16211622
raise UsageError(error_template.format(error=str(e)))
16221623
try:

src/_pytest/monkeypatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def resolve(name: str) -> object:
5555
parts = name.split(".")
5656

5757
used = parts.pop(0)
58-
found = __import__(used)
58+
found: object = __import__(used)
5959
for part in parts:
6060
used += "." + part
6161
try:

src/_pytest/pathlib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@ def import_path(
539539
ignore = os.environ.get("PY_IGNORE_IMPORTMISMATCH", "")
540540
if ignore != "1":
541541
module_file = mod.__file__
542+
if module_file is None:
543+
raise ImportPathMismatchError(module_name, module_file, path)
544+
542545
if module_file.endswith((".pyc", ".pyo")):
543546
module_file = module_file[:-1]
544547
if module_file.endswith(os.path.sep + "__init__.py"):

src/_pytest/python.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def reportinfo(self) -> Tuple[Union["os.PathLike[str]", str], Optional[int], str
330330
if isinstance(compat_co_firstlineno, int):
331331
# nose compatibility
332332
file_path = sys.modules[obj.__module__].__file__
333+
assert file_path is not None
333334
if file_path.endswith(".pyc"):
334335
file_path = file_path[:-1]
335336
path: Union["os.PathLike[str]", str] = file_path

testing/test_conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def test_value_access_with_confmod(self, basedir: Path) -> None:
114114
"a", startdir, importmode="prepend", rootpath=Path(basedir)
115115
)
116116
assert value == 1.5
117+
assert mod.__file__ is not None
117118
path = Path(mod.__file__)
118119
assert path.parent == basedir / "adir" / "b"
119120
assert path.stem == "conftest"
@@ -197,12 +198,14 @@ def test_conftestcutdir(pytester: Pytester) -> None:
197198
values = conftest._getconftestmodules(
198199
conf.parent, importmode="prepend", rootpath=pytester.path
199200
)
201+
assert values[0].__file__ is not None
200202
assert values[0].__file__.startswith(str(conf))
201203
# and all sub paths get updated properly
202204
values = conftest._getconftestmodules(
203205
p, importmode="prepend", rootpath=pytester.path
204206
)
205207
assert len(values) == 1
208+
assert values[0].__file__ is not None
206209
assert values[0].__file__.startswith(str(conf))
207210

208211

@@ -214,6 +217,7 @@ def test_conftestcutdir_inplace_considered(pytester: Pytester) -> None:
214217
conf.parent, importmode="prepend", rootpath=pytester.path
215218
)
216219
assert len(values) == 1
220+
assert values[0].__file__ is not None
217221
assert values[0].__file__.startswith(str(conf))
218222

219223

testing/test_pathlib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ def test_smoke_test(self, path1: Path) -> None:
143143
assert obj.x == 42 # type: ignore[attr-defined]
144144
assert obj.__name__ == "execfile"
145145

146+
def test_import_path_missing_file(self, path1: Path) -> None:
147+
with pytest.raises(ImportPathMismatchError):
148+
import_path(path1 / "sampledir", root=path1)
149+
146150
def test_renamed_dir_creates_mismatch(
147151
self, tmp_path: Path, monkeypatch: MonkeyPatch
148152
) -> None:

0 commit comments

Comments
 (0)