Skip to content

Commit f09c4f4

Browse files
committed
Update Ruff + mypy and fix some decorated types in sympy
1 parent 692c37c commit f09c4f4

File tree

6 files changed

+33
-46
lines changed

6 files changed

+33
-46
lines changed

pyproject.toml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ name = "microsoft-python-type-stubs"
77
version = "0"
88

99
[dependency-groups]
10-
hygiene = ["ruff ==0.11.*"]
10+
hygiene = ["ruff ==0.14.*"]
1111
tests = [
1212
# Tools used for testing
1313
"docopt-ng",
14-
"mypy ==1.16.*",
14+
"mypy ==1.19.*",
1515
"pyright",
1616

1717
# External type stubs and optional dependencies
@@ -55,15 +55,22 @@ target-version = "py39"
5555
extend-select = [
5656
"FA", # flake8-future-annotations
5757
"I", # isort
58-
"PGH", # pygrep-hooks
5958
"PGH", # pygrep-hooks and blanket-noqa
60-
"PIE790", # unnecessary-placeholder
59+
"PIE", # flake8-pie and unnecessary-placeholder
6160
"PYI", # flake8-pyi
6261
"RUF", # Ruff-specific and unused-noqa
62+
"TC", # flake8-type-checking
6363
"UP", # pyupgrade
6464
"W", # pycodestyle Warning
65+
"YTT", # flake8-2020 (version_info misuses)
6566
]
6667
ignore = [
68+
# Not colored correctly in Pylance https://github.com/microsoft/pylance-release/issues/6942
69+
"UP047",
70+
71+
# TODO: Investigate and fix or configure
72+
"PYI051", # Request for autofix: https://github.com/astral-sh/ruff/issues/14185
73+
6774
###
6875
# Rules we don't want or don't agree with
6976
###
@@ -77,9 +84,6 @@ ignore = [
7784
"PYI011",
7885
"PYI014",
7986
"PYI053",
80-
81-
# TODO: Investigate and fix or configure
82-
"PYI051", # Request for autofix: https://github.com/astral-sh/ruff/issues/14185
8387
]
8488

8589
[tool.ruff.lint.per-file-ignores]
@@ -144,13 +148,12 @@ reportSelfClsParameterName = false
144148
reportUnsupportedDunderAll = "error"
145149

146150
[tool.mypy]
151+
fixed_format_cache = true # Will be default in mypy 1.20
147152
strict = true
148-
check_untyped_defs = true # Strict check on all defs
149153
show_column_numbers = true
150154
# Not all imports in these stubs are gonna be typed
151155
# Don't infer symbols from untyped packages as Any
152156
follow_untyped_imports = true
153-
warn_unused_ignores = false # Change from pandas
154157
# Partial stubs are acceptable
155158
disallow_any_generics = false
156159
disallow_incomplete_defs = false
@@ -165,25 +168,30 @@ disable_error_code = [
165168
# as they are inherited from the implementation.
166169
"override",
167170
# TODO
168-
"assignment", # 744 errors in 155 files
171+
"assignment", # 688 errors in 155 files
169172
]
170173

171174
[[tool.mypy.overrides]]
172175
# follow_untyped_imports = true will cause stubtest to run mypy on the source
173176
# So disable it for partial stubs
174177
module = ["sympy.*"]
175178
follow_untyped_imports = false
176-
disable_error_code = ["import-untyped", "misc"]
179+
disable_error_code = [
180+
"import-untyped",
181+
# TODO
182+
"misc",
183+
]
177184

178185
[[tool.mypy.overrides]]
179186
# These modules are to be removed soon, not worth solving many issues
180-
module = ["matplotlib.*", "networkx.*"]
187+
module = ["matplotlib.*"]
188+
disable_error_code = ["assignment", "misc", "untyped-decorator"]
189+
190+
[[tool.mypy.overrides]]
191+
module = ["skimage.*", "sklearn.*"]
181192
disable_error_code = [
182-
"assignment",
193+
# TODO
183194
"misc",
195+
# TODO: Too many untyped decorators still left
196+
"untyped-decorator",
184197
]
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/sympy-stubs/stats/crv_types.pyi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ from typing_extensions import Self
44
from sympy import Equality, FiniteSet, Integral, Interval, Ne, Piecewise, Sum
55
from sympy.core.basic import Basic
66
from sympy.core.relational import Relational
7-
from sympy.matrices import MatrixBase
87
from sympy.stats.crv import SingleContinuousDistribution
98
from sympy.stats.joint_rv import JointRandomSymbol
10-
from sympy.stats.rv import RandomSymbol, is_random
9+
from sympy.stats.rv import RandomSymbol
1110

1211
oo = ...
1312
__all__ = [
@@ -66,8 +65,6 @@ __all__ = [
6665
"WignerSemicircle",
6766
]
6867

69-
@is_random.register(MatrixBase)
70-
def _(x) -> bool: ...
7168
def rv(symbol, cls, args, **kwargs) -> RandomSymbol: ...
7269

7370
class ContinuousDistributionHandmade(SingleContinuousDistribution):

stubs/sympy-stubs/stats/random_matrix_models.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from typing import Any, Literal
1+
from typing import Any
22
from typing_extensions import Self
33

44
from sympy import Equality, Integral, Ne
55
from sympy.core.basic import Basic
66
from sympy.core.function import Lambda
77
from sympy.core.relational import Relational
88
from sympy.stats.joint_rv_types import JointDistributionHandmade
9-
from sympy.stats.rv import Density, RandomMatrixSymbol, is_random
9+
from sympy.stats.rv import Density, RandomMatrixSymbol
1010

1111
__all__ = [
1212
"CircularEnsemble",
@@ -22,9 +22,6 @@ __all__ = [
2222
"level_spacing_distribution",
2323
]
2424

25-
@is_random.register(RandomMatrixSymbol)
26-
def _(x) -> Literal[True]: ...
27-
2825
class RandomMatrixEnsembleModel(Basic):
2926
def __new__(cls, sym, dim=...) -> Self: ...
3027

stubs/sympy-stubs/stats/rv.pyi

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections.abc import Generator
2-
from functools import singledispatch
32
from typing import Any
43
from typing_extensions import Self
54

@@ -24,10 +23,7 @@ from sympy.utilities.decorator import doctest_depends_on
2423

2524
x = ...
2625

27-
@singledispatch
28-
def is_random(x) -> bool: ...
29-
@is_random.register(Basic)
30-
def _(x) -> bool: ...
26+
def is_random(x: object) -> bool: ...
3127

3228
class RandomDomain(Basic):
3329
is_ProductDomain = ...

stubs/sympy-stubs/stats/stochastic_process_types.pyi

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Generator
2-
from typing import Any, Literal
2+
from typing import Any
33
from typing_extensions import Self
44

55
from sympy import Equality, Integral, Ne, Piecewise, Sum
@@ -23,7 +23,7 @@ from sympy.stats.drv_types import PoissonDistribution
2323
from sympy.stats.frv_types import BernoulliDistribution
2424
from sympy.stats.joint_rv import JointDistribution, JointRandomSymbol
2525
from sympy.stats.joint_rv_types import JointDistributionHandmade
26-
from sympy.stats.rv import Density, Distribution, RandomIndexedSymbol, RandomSymbol, is_random
26+
from sympy.stats.rv import Density, Distribution, RandomIndexedSymbol, RandomSymbol
2727
from sympy.stats.symbolic_multivariate_probability import ExpectationMatrix
2828
from sympy.stats.symbolic_probability import Expectation, Probability
2929
from sympy.tensor.indexed import Indexed
@@ -43,11 +43,6 @@ __all__ = [
4343
"GammaProcess",
4444
]
4545

46-
@is_random.register(Indexed)
47-
def _(x) -> bool: ...
48-
@is_random.register(RandomIndexedSymbol)
49-
def _(x) -> Literal[True]: ...
50-
5146
class StochasticProcess(Basic):
5247
index_set = ...
5348
def __new__(cls, sym, state_space=..., **kwargs) -> Self: ...

stubs/sympy-stubs/stats/symbolic_probability.pyi

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Literal
1+
from typing import Any
22
from typing_extensions import Self
33

44
from sympy import Basic, Equality, Integral, Ne, Piecewise, Sum
@@ -8,16 +8,10 @@ from sympy.core.function import Lambda
88
from sympy.core.relational import Relational
99
from sympy.series.order import Order
1010
from sympy.stats.frv_types import BernoulliDistribution
11-
from sympy.stats.rv import RandomSymbol, is_random
1211
from sympy.stats.symbolic_multivariate_probability import CrossCovarianceMatrix, ExpectationMatrix, VarianceMatrix
1312

1413
__all__ = ["Probability", "Expectation", "Variance", "Covariance"]
1514

16-
@is_random.register(Expr) # type: ignore[has-type]
17-
def _(x) -> bool: ...
18-
@is_random.register(RandomSymbol) # type: ignore[has-type]
19-
def _(x) -> Literal[True]: ...
20-
2115
class Probability(Expr):
2216
def __new__(cls, prob, condition=..., **kwargs) -> Self: ...
2317
def doit(self, **hints) -> Any | BernoulliDistribution | Probability | Equality | Lambda | Order | Relational | Ne | int: ...

0 commit comments

Comments
 (0)