Skip to content

Commit 33f11b7

Browse files
committed
tests: improve ignores for generated stdlib
1 parent 7abe1d4 commit 33f11b7

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

mypy/stubgen.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ def _get_namedtuple_fields(self, call: CallExpr) -> list[tuple[str, str]] | None
10481048
field_names.append(field.value)
10491049
else:
10501050
return None # Invalid namedtuple fields type
1051-
# if field_names:
1052-
# self.untyped
1051+
if not field_names:
1052+
return []
10531053
incomplete = self.untyped
10541054
return [(field_name, incomplete) for field_name in field_names]
10551055
elif self.is_typed_namedtuple(call):

mypy/test/data.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _case_fail(msg: str) -> NoReturn:
8686
# optionally followed by lines of text.
8787
item = first_item = test_items[0]
8888
test_modules.append("__main__")
89+
ignore = "\n# mypy: allow-untyped-defs, allow-any-explicit\n"
8990
for item in test_items[1:]:
9091

9192
def _item_fail(msg: str) -> NoReturn:
@@ -110,13 +111,13 @@ def _item_fail(msg: str) -> NoReturn:
110111
assert item.arg is not None
111112
mpath = join(os.path.dirname(case.file), item.arg)
112113
with open(mpath, encoding="utf8") as f:
113-
files.append((join(base_path, "builtins.pyi"), f.read()))
114+
files.append((join(base_path, "builtins.pyi"), f.read() + ignore))
114115
elif item.id == "typing":
115116
# Use an alternative stub file for the typing module.
116117
assert item.arg is not None
117118
src_path = join(os.path.dirname(case.file), item.arg)
118119
with open(src_path, encoding="utf8") as f:
119-
files.append((join(base_path, "typing.pyi"), f.read()))
120+
files.append((join(base_path, "typing.pyi"), f.read() + ignore))
120121
elif item.id == "_typeshed":
121122
# Use an alternative stub file for the _typeshed module.
122123
assert item.arg is not None

test-data/unit/fixtures/property.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class object:
66
def __init__(self) -> None: pass
77

88
class type:
9-
def __init__(self, x: object) -> None: pass
9+
def __init__(self, x: typing.Any) -> None: pass
1010

1111
class function: pass
1212

test-data/unit/fixtures/typing-full.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ from abc import abstractmethod, ABCMeta
1010

1111
class GenericMeta(type): pass
1212

13-
def cast(t: Any, o: Any) -> Any: ...
14-
def assert_type(o: Any, t: Any) -> Any: ...
13+
def cast(t, o): ...
14+
def assert_type(o, t): ...
1515
overload = 0
1616
Any = 0
1717
Union = 0

test-data/unit/fixtures/typing-medium.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Generator(Iterator[T], Generic[T, U, V]):
5252
def __iter__(self) -> 'Generator[T, U, V]': pass
5353

5454
class Sequence(Iterable[T_co]):
55-
def __getitem__(self, n: Any) -> T_co: pass # type: ignore[no-any-explicit, unused-ignore]
55+
def __getitem__(self, n: Any) -> T_co: pass
5656

5757
class Mapping(Iterable[T], Generic[T, T_co]):
5858
def keys(self) -> Iterable[T]: pass # Approximate return type
@@ -67,7 +67,7 @@ class SupportsFloat(Protocol):
6767
class ContextManager(Generic[T]):
6868
def __enter__(self) -> T: pass
6969
# Use Any because not all the precise types are in the fixtures.
70-
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass # type: ignore[no-any-explicit, unused-ignore]
70+
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass
7171

7272
class _SpecialForm: pass
7373

tox.ini

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ passenv =
5353
MYPY_FORCE_COLOR
5454
MYPY_FORCE_TERMINAL_WIDTH
5555
commands =
56-
# Do a legacy compatible check, this is needed because generating a baseline from the head of upstream
56+
# Do a no-strict compatible check, this is needed because generating a baseline from the head of upstream
5757
# sound very laborious
5858
python -m mypy --config-file mypy_self_check.ini --baseline-file= -p mypy -p mypyc --exclude misc/fix_annotate.py --exclude misc/async_matrix.py --exclude misc/sync-typeshed.py
5959
python -m mypy --config-file mypy_self_check_strict.ini -p mypy -p mypyc --exclude misc/fix_annotate.py --exclude misc/async_matrix.py --exclude misc/sync-typeshed.py
60-
python -m mypy --config-file mypy_self_check.ini --no-strict misc --exclude misc/fix_annotate.py --exclude misc/async_matrix.py --exclude misc/sync-typeshed.py

0 commit comments

Comments
 (0)