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 mypy_path = src
check_untyped_defs = True check_untyped_defs = True
disallow_any_generics = True disallow_any_generics = True
disallow_untyped_defs = True
ignore_missing_imports = True ignore_missing_imports = True
show_error_codes = True show_error_codes = True
strict_equality = True strict_equality = True

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Hook specifications for pytest plugins which are invoked by pytest itself """Hook specifications for pytest plugins which are invoked by pytest itself
and by builtin plugins.""" and by builtin plugins."""
from pathlib import Path 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 """Report test results in JUnit-XML format, for use with Jenkins and build
integration servers. integration servers.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
"""Terminal reporting of the full testing process. """Terminal reporting of the full testing process.
This is a good source for looking at the various reporting hooks. 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.""" """Support for providing temporary directories to test functions."""
import dataclasses import dataclasses
import os import os

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
# flake8: noqa # flake8: noqa
# disable flake check on this file because some constructs are strange # 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 # 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 dataclasses
import re import re
import sys import sys

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,3 +1,4 @@
# mypy: allow-untyped-defs
import unittest import unittest
import pytest 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.""" """Skipping an entire subclass with unittest.skip() should *not* call setUp from a base class."""
import unittest 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.""" """Skipping an entire subclass with unittest.skip() should *not* call setUpClass from a base class."""
import unittest 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""" """setUpModule is always called, even if all tests in the module are skipped"""
import unittest import unittest

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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