mypy: disallow untyped defs by default (#11862)

Change our mypy configuration to disallow untyped defs by default, which ensures *new* files added to the code base are fully typed.

To avoid having to type-annotate everything now, add `# mypy: allow-untyped-defs` to files which are not fully type annotated yet.

As we fully type annotate those modules, we can then just remove that directive from the top.
This commit is contained in:
Bruno Oliveira 2024-01-28 10:12:42 -03:00 committed by GitHub
parent e7b43b2121
commit 878af85aef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
155 changed files with 158 additions and 3 deletions

View File

@ -94,6 +94,7 @@ formats = sdist.tgz,bdist_wheel
mypy_path = src
check_untyped_defs = True
disallow_any_generics = True
disallow_untyped_defs = True
ignore_missing_imports = True
show_error_codes = True
strict_equality = True

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import ast
import dataclasses
import inspect

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import ast
import inspect
import textwrap

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
# This module was imported from the cpython standard library
# (https://github.com/python/cpython/) at commit
# c5140945c723ae6c4b7ee81ff720ac8ea4b52cfd (python3.12).

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""local path implementation."""
from __future__ import annotations

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Support for presenting detailed information in failing assertions."""
import sys
from typing import Any

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Utilities for assertion debugging."""
import collections.abc
import os

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Implementation of the cache provider."""
# This plugin was not named "cache" to avoid conflicts with the external
# pytest-cache version.

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Per-test stdout/stderr capturing mechanism."""
import abc
import collections

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Python version compatibility code."""
from __future__ import annotations

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Command line options, ini-file and conftest.py processing."""
import argparse
import collections.abc

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import argparse
import os
import sys

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Interactive debugging with PDB, the Python Debugger."""
import argparse
import functools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Discover and run doctests in modules and test files."""
import bdb
import functools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import abc
import dataclasses
import functools

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Version info, help messages, tracing configuration."""
import os
import sys

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Hook specifications for pytest plugins which are invoked by pytest itself
and by builtin plugins."""
from pathlib import Path

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Report test results in JUnit-XML format, for use with Jenkins and build
integration servers.

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Add backward compatibility support for the legacy py path type."""
import dataclasses
import os

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Access and control log capturing."""
import io
import logging

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import collections.abc
import dataclasses
import inspect

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Monkeypatching and mocking functionality."""
import os
import re

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import abc
import os
import warnings

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Submit failure or test session information to a pastebin service."""
import tempfile
from io import StringIO

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import atexit
import contextlib
import fnmatch

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""(Disabled by default) support for testing pytest and pytest plugins.
PYTEST_DONT_REWRITE

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Python test discovery, setup and run of test functions."""
import abc
import dataclasses

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import math
import pprint
from collections.abc import Collection

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Record warnings during test function execution."""
import re
import warnings

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import dataclasses
import os
from io import StringIO

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Basic collect and runtest protocol implementations."""
import bdb
import dataclasses

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Support for skip/xfail functions and markers."""
import dataclasses
import os

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Terminal reporting of the full testing process.
This is a good source for looking at the various reporting hooks.

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Support for providing temporary directories to test functions."""
import dataclasses
import os

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Discover and run std-library "unittest" style tests."""
import sys
import traceback

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import sys
import warnings
from contextlib import contextmanager

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import contextlib
import multiprocessing
import os

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import dataclasses
import importlib.metadata
import os

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import re
import sys
from types import FrameType

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
from __future__ import annotations
import importlib

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
# flake8: noqa
# disable flake check on this file because some constructs are strange
# or redundant on purpose and can't be disable on a line-by-line basis

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import dataclasses
import re
import sys

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest
from _pytest import deprecated
from _pytest.pytester import Pytester

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Reproduces issue #3774"""
from unittest import mock

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_init():
pass

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_foo():
pass

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def pytest_ignore_collect(collection_path):
return False

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test():
pass

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_init():
pass

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_foo():
pass

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_foo():
pass

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
def pytest_configure(config):
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
# content of conftest.py
import json

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
# content of test_first.py
def test_1():
pass

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
# content of test_second.py
def test_2():
pass

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
# content of test_third.py
def test_3():
pass

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
from dataclasses import dataclass
from dataclasses import InitVar

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
from dataclasses import dataclass

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_this_is_ignored():
assert True

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
def test_doc():
"""
>>> 10 > 5

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test():
pass

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_1(arg1):
pass

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_2(arg2):
pass

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_spam(spam):
assert spam == "spamspam"

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_hello():
pass

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pprint
from typing import List
from typing import Tuple

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import argparse
import pathlib

View File

@ -1,2 +1,3 @@
# mypy: allow-untyped-defs
def test_x():
pass

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import unittest
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Skipping an entire subclass with unittest.skip() should *not* call setUp from a base class."""
import unittest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Skipping an entire subclass with unittest.skip() should *not* call setUpClass from a base class."""
import unittest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""setUpModule is always called, even if all tests in the module are skipped"""
import unittest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
from typing import List
from unittest import IsolatedAsyncioTestCase

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Issue #7110"""
import asyncio
from typing import List

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import unittest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import warnings
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import warnings
import pytest

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
from test_1 import func

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
def test_upper():
assert "foo".upper() == "FOO"

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import pytest
from _pytest._io.saferepr import DEFAULT_REPR_MAX_SIZE
from _pytest._io.saferepr import saferepr

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import io
import os
import re

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import io
import os
import re

Some files were not shown because too many files have changed in this diff Show More