Skip to content

Commit e853bb1

Browse files
committed
Disallow Any on public interface types
1 parent 6a7df7f commit e853bb1

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Nicholas Murphy
204204
Niclas Olofsson
205205
Nicolas Delaby
206206
Nikolay Kondratyev
207+
Nipunn Koorapati
207208
Oleg Pidsadnyi
208209
Oleg Sushchenko
209210
Oliver Bestwalter

setup.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,18 @@ strict_equality = True
7070
warn_redundant_casts = True
7171
warn_return_any = True
7272
warn_unused_configs = True
73+
74+
# Hold the public interface to a higher standard
75+
[mypy-pytest]
76+
# Disallow dynamic typing
77+
disallow_any_decorated = True
78+
disallow_any_expr = True
79+
disallow_any_generics = True
80+
disallow_any_unimported = True
81+
disallow_subclassing_any = True
82+
83+
# Disallow untyped definitions/calls
84+
disallow_incomplete_defs = True
85+
disallow_untyped_calls = True
86+
disallow_untyped_decorators = True
87+
disallow_untyped_defs = True

src/_pytest/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
__all__ = ["__version__"]
22

33
try:
4-
from ._version import version as __version__
4+
from ._version import version
5+
__version__: str = version
56
except ImportError:
67
# broken installation, we don't even try
78
# unknown only works because we do poor mans version compare

src/pytest/__init__.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,57 @@
4646
from _pytest.warning_types import PytestUnknownMarkWarning
4747
from _pytest.warning_types import PytestWarning
4848

49+
# For mypy Any type checking purposes.
50+
# This file sets disallow_any_expr to ensure that the public API
51+
# does not have dynamic typing via Any. Manually using each public API
52+
# type as an expression to enforce this.
53+
__version__ = __version__
54+
register_assert_rewrite = register_assert_rewrite
55+
_setup_collect_fakemodule = _setup_collect_fakemodule
56+
cmdline = cmdline
57+
ExitCode = ExitCode
58+
#hookimpl = hookimpl
59+
#hookspec = hookspec
60+
main = main
61+
UsageError = UsageError
62+
__pytestPDB = __pytestPDB
63+
_fillfuncargs = _fillfuncargs
64+
fixture = fixture
65+
yield_fixture = yield_fixture
66+
freeze_includes = freeze_includes
67+
Session = Session
68+
mark = mark
69+
param = param
70+
Collector = Collector
71+
File = File
72+
Item = Item
73+
exit = exit
74+
fail = fail
75+
importorskip = importorskip
76+
skip = skip
77+
xfail = xfail
78+
Class = Class
79+
Function = Function
80+
Instance = Instance
81+
Module = Module
82+
Package = Package
83+
approx = approx
84+
raises = raises
85+
deprecated_call = deprecated_call
86+
warns = warns
87+
PytestAssertRewriteWarning = PytestAssertRewriteWarning
88+
PytestCacheWarning = PytestCacheWarning
89+
PytestCollectionWarning = PytestCollectionWarning
90+
PytestConfigWarning = PytestConfigWarning
91+
PytestDeprecationWarning = PytestDeprecationWarning
92+
PytestExperimentalApiWarning = PytestExperimentalApiWarning
93+
PytestUnhandledCoroutineWarning = PytestUnhandledCoroutineWarning
94+
PytestUnknownMarkWarning = PytestUnknownMarkWarning
95+
PytestWarning = PytestWarning
4996

50-
set_trace = __pytestPDB.set_trace
97+
98+
# Allow set_trace() to be typed with None
99+
set_trace = __pytestPDB.set_trace # type: ignore[misc]
51100

52101
__all__ = [
53102
"__version__",

0 commit comments

Comments
 (0)