Skip to content

Commit 193bda6

Browse files
authored
Merge branch 'main' into metrics
2 parents bda81cc + b311fd7 commit 193bda6

File tree

830 files changed

+11117
-5456
lines changed

Some content is hidden

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

830 files changed

+11117
-5456
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,51 @@
1-
name: 'Test'
1+
name: "Test"
22

33
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
2129
with:
2230
path: ~/.cache/pip
23-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
31+
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
2432
restore-keys: |
2533
${{ runner.os }}-pip-
2634
2735
- name: Install dependencies
28-
run:
29-
python -m pip install -r tests/requirements.txt
36+
run: python -m pip install --group tests
3037

3138
- name: Run pyright tests
3239
uses: jakebailey/pyright-action@v2
3340
with:
3441
pylance-version: latest-prerelease
42+
python-version: ${{ matrix.python-version }}
3543

3644
- name: Run mypy tests
37-
run:
38-
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
3949

4050
hygiene:
4151
runs-on: ubuntu-latest
@@ -47,6 +57,5 @@ jobs:
4757

4858
- name: Run Ruff Linter
4959
uses: astral-sh/ruff-action@v3
50-
with:
51-
version: "0.9.*"
52-
- 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: 97 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,34 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "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
2753
target-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
]
3664
ignore = [
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]
61106
combine-as-imports = true
62107
extra-standard-library = [
@@ -66,10 +111,9 @@ extra-standard-library = [
66111
]
67112

68113
[tool.pyright]
69-
exclude = ["build", ".git"]
114+
exclude = ["build", ".git", ".venv*"]
70115
stubPath = "./stubs"
71-
# Target oldest supported Python version
72-
pythonversion = "3.9"
116+
pythonversion = "3.9" # Target oldest supported Python version
73117
typeCheckingMode = "standard"
74118
# Partial stubs are acceptable
75119
reportUnknownArgumentType = false
@@ -93,42 +137,46 @@ reportSelfClsParameterName = false
93137
reportUnsupportedDunderAll = "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
113146
warn_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
115152
disable_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"]

stubs/matplotlib/__init__.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
2-
from typing import Generator, Literal
2+
from collections.abc import Generator
3+
from typing import Literal
34

45
import numpy as np
56
from packaging.version import parse as parse_version

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/_api/__init__.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
2-
from typing import Any, Callable, Generator, Iterable, Type
2+
from collections.abc import Generator, Iterable
3+
from typing import Callable
34

45
from .deprecation import MatplotlibDeprecationWarning
56

@@ -19,5 +20,5 @@ def select_matching_signature(funcs: list[Callable], *args, **kwargs): ...
1920
def recursive_subclasses(cls) -> Generator: ...
2021
def warn_external(
2122
message: MatplotlibDeprecationWarning | PendingDeprecationWarning | str,
22-
category: None | Type[MatplotlibDeprecationWarning] = ...,
23+
category: None | type[MatplotlibDeprecationWarning] = ...,
2324
) -> None: ...

stubs/matplotlib/_api/deprecation.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
2+
from collections.abc import Iterator
23
from functools import partial
3-
from typing import Callable, Iterator
4+
from typing import Callable
45

56
class MatplotlibDeprecationWarning(DeprecationWarning): ...
67

stubs/matplotlib/_mathtext.pyi

Lines changed: 21 additions & 5 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:
@@ -64,7 +71,7 @@ class DejaVuSansFonts(DejaVuFonts): ...
6471

6572
class StixFonts(UnicodeFonts):
6673
def __init__(self, *args, **kwargs) -> None: ...
67-
@functools.lru_cache()
74+
@functools.lru_cache
6875
def get_sized_alternatives_for_symbol(self, fontname, sym) -> list[tuple]: ...
6976

7077
class StixSansFonts(StixFonts): ...
@@ -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/_pylab_helpers.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, OrderedDict
1+
from collections import OrderedDict
22

33
from .backend_bases import FigureManagerBase
44
from .figure import Figure

0 commit comments

Comments
 (0)