@@ -4,7 +4,34 @@ build-backend = "setuptools.build_meta"
44
55[project ]
66name = " microsoft-python-type-stubs"
7- dynamic = [" version" ]
7+ version = " 0"
8+
9+ [dependency-groups ]
10+ hygiene = [" ruff ==0.11.*" ]
11+ tests = [
12+ # Tools used for testing
13+ " docopt-ng" ,
14+ " mypy ==1.15.*" ,
15+ " pyright" ,
16+
17+ # External type stubs and optional dependencies
18+ " PyOpenGL" ,
19+ " matplotlib >=3.8" ,
20+ " pandas-stubs" ,
21+ " pytest" ,
22+ " scipy-stubs" ,
23+ " typing_extensions" ,
24+
25+ # The libraries we're stubbing.
26+ # Needed for stubtest and downloads their dependencies to get known import symbols
27+ " networkx" ,
28+ " scikit-image" ,
29+ " scikit-learn" ,
30+ " sympy" ,
31+ " vispy" ,
32+ ]
33+ dev = [{ include-group = " hygiene" }, { include-group = " tests" }]
34+
835
936# Allow these stubs to be installed from GitHub
1037# We need an explicit mapping instead of just
@@ -18,7 +45,6 @@ dynamic = ["version"]
1845"skimage-stubs" = " stubs/skimage"
1946"sklearn-stubs" = " stubs/sklearn"
2047"sympy-stubs" = " stubs/sympy-stubs"
21- "transformers-stubs" = " stubs/transformers-stubs"
2248"vispy-stubs" = " stubs/vispy"
2349
2450[tool .ruff ]
@@ -27,36 +53,55 @@ line-length = 130
2753target-version = " py39"
2854
2955[tool .ruff .lint ]
30- # TODO: Use extend-select instead to get base E and F rules that don't conflict with the formatter
31- select = [
56+ extend-select = [
3257 " FA" , # flake8-future-annotations
3358 " I" , # isort
3459 " PYI" , # flake8-pyi
60+ " UP" , # pyupgrade
61+ " W" , # pycodestyle Warning
62+ " PIE790" , # unnecessary-placeholder
3563]
3664ignore = [
3765 # ##
3866 # Rules we don't want or don't agree with
3967 # ##
68+
69+ # Used for direct, non-subclass type comparison, for example: `type(val) is str`
70+ # see https://github.com/astral-sh/ruff/issues/6465
71+ " E721" , # Do not compare types, use `isinstance()`
72+
4073 # Typeshed doesn't want complex or non-literal defaults, or long strings, for maintenance and testing reasons.
4174 # This doesn't affect us, let's have more complete stubs.
4275 " PYI011" ,
4376 " PYI014" ,
4477 " PYI053" ,
4578
46- # TODO: Handle in its own PR
47- " PYI021" , # https://github.com/microsoft/python-type-stubs/pull/343
48-
4979 # TODO: Investigate and fix or configure
50- " PYI001" ,
51- " PYI002" ,
52- " PYI017" ,
53- " PYI019" , # Request for more autofixes: https://github.com/astral-sh/ruff/issues/15798
54- " PYI024" ,
55- " PYI048" ,
5680 " PYI051" , # Request for autofix: https://github.com/astral-sh/ruff/issues/14185
57- " PYI052" ,
5881]
5982
83+ [tool .ruff .lint .per-file-ignores ]
84+ "*.pyi" = [
85+ # ##
86+ # Rules that are out of the control of stub authors:
87+ # ##
88+ " E743" , # Ambiguous function name; stubs must follow implementation
89+ " F403" , # `from . import *` used; unable to detect undefined names
90+ # Stubs can sometimes re-export entire modules.
91+ # Issues with using a star-imported name will be caught by type-checkers.
92+ " F405" , # may be undefined, or defined from star imports
93+ ]
94+
95+ # We keep docstrings in sklearn
96+ "stubs/sklearn/**" = [" PYI021" ]
97+
98+ # TODO: For public modules, manually evaluate each violation.
99+ # Removing unused imports change which symbols are even visible for Pylance.
100+ # Which may negatively affect users, especially if the symbol wasn't meant to be re-exported.
101+ # We do assume no public re-exports were meant from private modules
102+ "!_*.pyi" = [" F401" ]
103+ "__init__.pyi" = [" F401" ]
104+
60105[tool .ruff .lint .isort ]
61106combine-as-imports = true
62107extra-standard-library = [
@@ -66,10 +111,9 @@ extra-standard-library = [
66111]
67112
68113[tool .pyright ]
69- exclude = [" build" , " .git" ]
114+ exclude = [" build" , " .git" , " .venv* " ]
70115stubPath = " ./stubs"
71- # Target oldest supported Python version
72- pythonversion = " 3.9"
116+ pythonversion = " 3.9" # Target oldest supported Python version
73117typeCheckingMode = " standard"
74118# Partial stubs are acceptable
75119reportUnknownArgumentType = false
@@ -93,42 +137,46 @@ reportSelfClsParameterName = false
93137reportUnsupportedDunderAll = " error"
94138
95139[tool .mypy ]
96- # Target oldest supported Python version
97- python_version = " 3.9"
98- # Allow dynamic typing
99- disallow_any_unimported = false # TODO
100- disallow_any_expr = false # TODO
101- disallow_any_decorated = false # TODO
102- disallow_any_explicit = false # TODO
103- disallow_any_generics = false # TODO
104- disallow_subclassing_any = false # TODO
105- # Untyped definitions and calls
106- disallow_untyped_calls = false # TODO
107- disallow_untyped_defs = false # TODO
108- disallow_incomplete_defs = false # TODO
109- check_untyped_defs = true
110- disallow_untyped_decorators = true
111- # Configuring warnings
112- warn_redundant_casts = true
140+ strict = true
141+ check_untyped_defs = true # Strict check on all defs
142+ show_column_numbers = true
143+ # Not all imports in these stubs are gonna be typed
144+ # Don't infer symbols from untyped packages as Any
145+ follow_untyped_imports = true
113146warn_unused_ignores = false # Change from pandas
147+ # Partial stubs are acceptable
148+ disallow_any_generics = false
149+ disallow_incomplete_defs = false
150+ disallow_untyped_defs = false
114151# Suppressing errors
115152disable_error_code = [
116- # Not all imports in these stubs are gonna be typed
117- " import-untyped " ,
118- # TODO
153+ # mypy's overload implementation differs from pyright
154+ # `assert-type` issues is tests mostly comme from checking overloads
155+ # Since this project is specific to Pylance, just ignore them
119156 " assert-type" ,
157+ # Incompatible overrides are out of our stubs' control
158+ # as they are inherited from the implementation.
159+ " override" ,
160+ # TODO
161+ " assignment" , # 744 errors in 155 files
162+ ]
163+
164+ [[tool .mypy .overrides ]]
165+ # follow_untyped_imports = true will cause stubtest to run mypy on the source
166+ # So disable it for partial stubs
167+ module = [" sympy.*" ]
168+ follow_untyped_imports = false
169+ disable_error_code = [" import-untyped" , " misc" ]
170+
171+ [[tool .mypy .overrides ]]
172+ # These modules are to be removed soon, not worth solving many issues
173+ module = [" matplotlib.*" , " networkx.*" ]
174+ disable_error_code = [
120175 " assignment" ,
121- " attr-defined" ,
122- " import-not-found" ,
123176 " misc" ,
124- " name-defined" ,
125- " no-redef" ,
126- " operator" ,
127- " override" ,
128- " return" ,
129- " type-var" ,
130- " valid-type" ,
131- " var-annotated" ,
132177]
133- # Configuring error messages
134- show_column_numbers = true
178+ [[tool .mypy .overrides ]]
179+ module = [" skimage.*" , " sklearn.*" ]
180+ # TODO: Too many untyped decorators still left
181+ # https://github.com/python/mypy/issues/19148
182+ disable_error_code = [" misc" ]
0 commit comments