Skip to content

Commit cf04b8a

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/python-type-stubs into remove-networkx
2 parents 3a1c8d6 + 76ca370 commit cf04b8a

411 files changed

Lines changed: 10874 additions & 3583 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ on: [push, pull_request, workflow_dispatch]
44

55
jobs:
66
test:
7-
runs-on: ubuntu-latest
7+
runs-on: ${{ matrix.os }}
88
timeout-minutes: 10
9+
strategy:
10+
matrix:
11+
# Oldest non-EOL and newest released
12+
# scipy-stubs does not support Python 3.9
13+
python-version: ["3.10", "3.13"]
14+
# Tier 1 OSes
15+
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
16+
fail-fast: false
917

1018
steps:
1119
- name: Check out code
1220
uses: actions/checkout@v2
1321

14-
- name: Setup Python
22+
- name: Setup Python ${{ matrix.python-version }}
1523
uses: actions/setup-python@v2
1624
with:
17-
python-version: "3.11"
25+
python-version: ${{ matrix.python-version }}
1826

1927
- name: Cache pip
2028
uses: actions/cache@v4
@@ -31,9 +39,13 @@ jobs:
3139
uses: jakebailey/pyright-action@v2
3240
with:
3341
pylance-version: latest-prerelease
42+
python-version: ${{ matrix.python-version }}
3443

3544
- name: Run mypy tests
36-
run: python -m mypy .
45+
run: python -m mypy . --python-version=${{ matrix.python-version }}
46+
47+
- name: Run stubtest
48+
run: python tests/run_stubtest.py
3749

3850
hygiene:
3951
runs-on: ubuntu-latest
@@ -45,4 +57,5 @@ jobs:
4557

4658
- name: Run Ruff Linter
4759
uses: astral-sh/ruff-action@v3
48-
- run: ruff format --check
60+
- name: Run Ruff Formatter
61+
run: ruff format --check

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ MigrationBackup/
357357
# Python virtual environment
358358
.venv
359359

360+
# Lock files (like uv.lock)
361+
*.lock
362+
360363
# Build files from utils
361364
.eggs
362365
*.egg-info

.vscode/settings.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"editor.formatOnSave": false,
3-
"python.formatting.provider": "black",
43
"python.analysis.diagnosticMode": "workspace",
5-
"python.analysis.openFilesOnly": false
4+
"[python]": {
5+
"editor.formatOnSave": true,
6+
"editor.defaultFormatter": "charliermarsh.ruff"
7+
}
68
}

pyproject.toml

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@ hygiene = ["ruff ==0.11.*"]
1111
tests = [
1212
# Tools used for testing
1313
"docopt-ng",
14-
"mypy ==1.13.*",
14+
"mypy ==1.16.*",
1515
"pyright",
1616

17-
# Typed libraries and stubs
17+
# External type stubs and optional dependencies
1818
"matplotlib >=3.8",
1919
"pandas-stubs",
20+
"PyOpenGL",
2021
"pytest",
2122
"scipy-stubs",
22-
"typing_extensions",
23-
24-
# Untyped libraries, used to prevent "reportMissingImports" and get inferred typing
25-
"joblib",
2623
"types-networkx",
27-
"PyOpenGL",
24+
"typing_extensions",
25+
26+
# The libraries we're stubbing.
27+
# Needed for stubtest and downloads their dependencies to get known import symbols
28+
"scikit-image",
2829
"scikit-learn",
2930
"sympy",
30-
"traitlets",
31-
"transformers",
31+
"vispy",
3232
]
3333
dev = [{ include-group = "hygiene" }, { include-group = "tests" }]
3434

@@ -44,7 +44,6 @@ dev = [{ include-group = "hygiene" }, { include-group = "tests" }]
4444
"skimage-stubs" = "stubs/skimage"
4545
"sklearn-stubs" = "stubs/sklearn"
4646
"sympy-stubs" = "stubs/sympy-stubs"
47-
"transformers-stubs" = "stubs/transformers-stubs"
4847
"vispy-stubs" = "stubs/vispy"
4948

5049
[tool.ruff]
@@ -56,10 +55,13 @@ target-version = "py39"
5655
extend-select = [
5756
"FA", # flake8-future-annotations
5857
"I", # isort
58+
"PGH", # pygrep-hooks
59+
"PGH", # pygrep-hooks and blanket-noqa
60+
"PIE790", # unnecessary-placeholder
5961
"PYI", # flake8-pyi
62+
"RUF", # Ruff-specific and unused-noqa
6063
"UP", # pyupgrade
6164
"W", # pycodestyle Warning
62-
"PIE790", # unnecessary-placeholder
6365
]
6466
ignore = [
6567
###
@@ -76,16 +78,17 @@ ignore = [
7678
"PYI014",
7779
"PYI053",
7880

79-
# TODO: Fixing these would change which symbols are even visible for Pylance.
80-
# Which may negatively affect users, especially if the symbol wasn't meant to be re-exported.
81-
# Manually evaluate each violation.
82-
"F401",
83-
8481
# TODO: Investigate and fix or configure
8582
"PYI051", # Request for autofix: https://github.com/astral-sh/ruff/issues/14185
8683
]
84+
8785
[tool.ruff.lint.per-file-ignores]
8886
"*.pyi" = [
87+
# Ruff 0.8.0 added sorting of __all__ and __slots_.
88+
# There is no consensus in typeshed on whether they want to apply this to stubs, so keeping the status quo.
89+
# See https://github.com/python/typeshed/pull/13108
90+
"RUF022", # `__all__` is not sorted
91+
"RUF023", # `{}.__slots__` is not sorted
8992
###
9093
# Rules that are out of the control of stub authors:
9194
###
@@ -99,6 +102,13 @@ ignore = [
99102
# We keep docstrings in sklearn
100103
"stubs/sklearn/**" = ["PYI021"]
101104

105+
# TODO: For public modules, manually evaluate each violation.
106+
# Removing unused imports change which symbols are even visible for Pylance.
107+
# Which may negatively affect users, especially if the symbol wasn't meant to be re-exported.
108+
# We do assume no public re-exports were meant from private modules
109+
"!_*.pyi" = ["F401"]
110+
"__init__.pyi" = ["F401"]
111+
102112
[tool.ruff.lint.isort]
103113
combine-as-imports = true
104114
extra-standard-library = [
@@ -108,7 +118,7 @@ extra-standard-library = [
108118
]
109119

110120
[tool.pyright]
111-
exclude = ["build", ".git"]
121+
exclude = ["build", ".git", ".venv*"]
112122
stubPath = "./stubs"
113123
pythonversion = "3.9" # Target oldest supported Python version
114124
typeCheckingMode = "standard"
@@ -134,24 +144,46 @@ reportSelfClsParameterName = false
134144
reportUnsupportedDunderAll = "error"
135145

136146
[tool.mypy]
137-
python_version = "3.9" # Target oldest supported Python version
138147
strict = true
139148
check_untyped_defs = true # Strict check on all defs
140149
show_column_numbers = true
150+
# Not all imports in these stubs are gonna be typed
151+
# Don't infer symbols from untyped packages as Any
152+
follow_untyped_imports = true
141153
warn_unused_ignores = false # Change from pandas
142154
# Partial stubs are acceptable
143155
disallow_any_generics = false
144156
disallow_incomplete_defs = false
145157
disallow_untyped_defs = false
146158
# Suppressing errors
147159
disable_error_code = [
148-
# Not all imports in these stubs are gonna be typed
149-
"import-untyped",
160+
# mypy's overload implementation differs from pyright
161+
# `assert-type` issues is tests mostly comme from checking overloads
162+
# Since this project is specific to Pylance, just ignore them
163+
"assert-type",
164+
# Incompatible overrides are out of our stubs' control
165+
# as they are inherited from the implementation.
166+
"override",
150167
# TODO
151-
"valid-type", # 967 errors in 115 files
152-
"override", # 790 errors in 220 files
153-
"assignment", # 773 errors in 172 files
154-
"misc", # 692 errors in 132 files
155-
"attr-defined", # 202 errors in 75 files
156-
"assert-type", # 6 errors in 1 file
168+
"assignment", # 744 errors in 155 files
169+
]
170+
171+
[[tool.mypy.overrides]]
172+
# follow_untyped_imports = true will cause stubtest to run mypy on the source
173+
# So disable it for partial stubs
174+
module = ["sympy.*"]
175+
follow_untyped_imports = false
176+
disable_error_code = ["import-untyped", "misc"]
177+
178+
[[tool.mypy.overrides]]
179+
# These modules are to be removed soon, not worth solving many issues
180+
module = ["matplotlib.*", "networkx.*"]
181+
disable_error_code = [
182+
"assignment",
183+
"misc",
157184
]
185+
[[tool.mypy.overrides]]
186+
module = ["skimage.*", "sklearn.*"]
187+
# TODO: Too many untyped decorators still left
188+
# https://github.com/python/mypy/issues/19148
189+
disable_error_code = ["misc"]

stubs/matplotlib/_afm.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import numpy as np
2-
31
from ._typing import *
42

53
CharMetrics = ...

stubs/matplotlib/_mathtext.pyi

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import enum
22
import functools
3-
from sre_parse import State
4-
from tkinter.tix import HList
3+
import sys
4+
from _typeshed import Incomplete
55
from typing import Literal
66

77
from .font_manager import FontProperties
88
from .mathtext import MathtextBackend
99

10+
# tkinter.tix was removed from Python 3.13
11+
# Recent matplotlib versions define HList in this module
12+
if sys.version_info >= (3, 13):
13+
HList = Incomplete
14+
else:
15+
from tkinter.tix import HList
16+
1017
def get_unicode_index(symbol: str, math: bool = True) -> int: ...
1118

1219
class Fonts:
@@ -143,14 +150,23 @@ class List(Box):
143150

144151
class Hlist(List):
145152
def __init__(
146-
self, elements, w: float = 0, m: Literal["exactly", "additional"] = "additional", do_kern: bool = True
153+
self,
154+
elements,
155+
w: float = 0,
156+
m: Literal["exactly", "additional"] = "additional",
157+
do_kern: bool = True,
147158
) -> None: ...
148159
def kern(self) -> None: ...
149160
def hpack(self, w: float = 0, m: Literal["exactly", "additional"] = "additional") -> None: ...
150161

151162
class Vlist(List):
152163
def __init__(self, elements, h=0, m=...) -> None: ...
153-
def vpack(self, h: float = ..., m: Literal["exactly", "additional"] = "additional", l: float = ...) -> None: ...
164+
def vpack(
165+
self,
166+
h: float = ...,
167+
m: Literal["exactly", "additional"] = "additional",
168+
l: float = ...,
169+
) -> None: ...
154170

155171
class Rule(Box):
156172
def __init__(self, width: float, height: float, depth: float, state) -> None: ...

stubs/matplotlib/_typing.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import decimal
21
import io
32
import typing_extensions
3+
from decimal import Decimal as Decimal
44

5-
import numpy.typing
65
import pandas as pd
6+
from numpy.typing import ArrayLike as ArrayLike
77

8-
Decimal = decimal.Decimal
98
PythonScalar: typing_extensions.TypeAlias = str | int | float | bool
109

11-
ArrayLike = numpy.typing.ArrayLike
1210
FileLike = io.IOBase
1311
PathLike = str
1412

stubs/matplotlib/axes/_axes.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
22
from collections.abc import Sequence
3-
from re import L
43
from typing import Callable, Literal, overload
54

65
import matplotlib.tri as mtri

stubs/matplotlib/axes/_secondary_axes.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Callable, Literal
22

3-
import numpy as np
43
from matplotlib._typing import *
54
from matplotlib.axes._base import _AxesBase
65
from matplotlib.transforms import Transform

stubs/matplotlib/backend_bases.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class FigureCanvasBase:
310310
def mpl_connect(self, s: str, func: Callable) -> int: ...
311311
def mpl_disconnect(self, cid: int): ...
312312
_timer_cls = TimerBase
313-
def new_timer(self, interval: int = ..., callbacks: list[tuple[Callable, tuple, dict]] = ...) -> _timer_cls: ...
313+
def new_timer(self, interval: int = ..., callbacks: list[tuple[Callable, tuple, dict]] = ...) -> TimerBase: ...
314314
def flush_events(self) -> None: ...
315315
def start_event_loop(self, timeout: int = ...) -> None: ...
316316
def stop_event_loop(self) -> None: ...

0 commit comments

Comments
 (0)