Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect inlay hints for generics where one of the types is a tuple #901

Merged
merged 2 commits into from
Nov 24, 2024

Conversation

DetachHead
Copy link
Owner

fixes #871

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stderr="error: branch '4e8031e9982a42390653aa7eb2bb45a235daab43' not found\n"
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stdout=''
sympy (https://github.com/sympy/sympy)
-     Type of "factor" is "(f: Unknown, ..., deep: bool = False) -> (Unknown | Add | Order | Mul)" (reportUnknownVariableType)
+     Type of "factor" is "(f: Unknown, ..., deep: bool = False) -> (Unknown | Add | Order | Mul | Expr)" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:104:9 - warning: Return type, "tuple[int, list[_NotImplementedType | Unknown | Any | bool], Any]", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:104:9 - warning: Return type, "tuple[int, list[_NotImplementedType | Unknown | Any | GreaterThan | Equality | Relational | Unequality | LessThan | bool], Any]", is partially unknown (reportUnknownParameterType)
-     Type of "constraints" is "list[_NotImplementedType | Unknown | Any | bool]" (reportUnknownVariableType)
+     Type of "constraints" is "list[_NotImplementedType | Unknown | Any | GreaterThan | Equality | Relational | Unequality | LessThan | bool]" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:114:16 - warning: Return type, "tuple[int, list[_NotImplementedType | Unknown | Any | bool], Any]", is partially unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:114:16 - warning: Return type, "tuple[int, list[_NotImplementedType | Unknown | Any | GreaterThan | Equality | Relational | Unequality | LessThan | bool], Any]", is partially unknown (reportUnknownVariableType)
-     Type of "system" is "list[_NotImplementedType | Unknown]" (reportUnknownVariableType)
+     Type of "system" is "list[_NotImplementedType | StrictLessThan | Unknown | Equality | Relational | Unequality | StrictGreaterThan]" (reportUnknownVariableType)
-     Type of "system" is "list[_NotImplementedType | Unknown]" (reportUnknownVariableType)
+     Type of "system" is "list[_NotImplementedType | StrictLessThan | Unknown | Equality | Relational | Unequality | StrictGreaterThan]" (reportUnknownVariableType)
-     Argument type is "Generator[_NotImplementedType | Unknown, None, None]" (reportUnknownArgumentType)
+     Argument type is "Generator[_NotImplementedType | StrictLessThan | Unknown | Equality | Relational | Unequality, None, None]" (reportUnknownArgumentType)
-     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Any)" (reportUnknownMemberType)
+     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Unknown)" (reportUnknownMemberType)
-     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Any)" (reportUnknownMemberType)
+     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Unknown)" (reportUnknownMemberType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solveset.py:1267:5 - warning: Type of "f1" is partially unknown
+     Type of "f1" is "Expr | Unknown" (reportUnknownVariableType)
-     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Any)" (reportUnknownMemberType)
+     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Unknown)" (reportUnknownMemberType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solveset.py:1268:5 - warning: Type of "f2" is partially unknown
+     Type of "f2" is "Expr | Unknown" (reportUnknownVariableType)
-     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Any)" (reportUnknownMemberType)
+     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Unknown)" (reportUnknownMemberType)
-     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Any)" (reportUnknownMemberType)
+     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Unknown)" (reportUnknownMemberType)
-     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Any)" (reportUnknownMemberType)
+     Type of "rewrite" is "(..., deep: bool = True) -> (Expr | Unknown)" (reportUnknownMemberType)
-     Type of "eq" is "_NotImplementedType | Unknown" (reportUnknownVariableType)
+     Type of "eq" is "_NotImplementedType | GreaterThan | Unknown | Equality | Relational | Unequality" (reportUnknownVariableType)
-     Type of "P" is "(condition: Unknown, given_condition: Unknown | None = None, numsamples: Unknown | None = None, evaluate: bool = True, **kwargs: Unknown) -> (Unknown | Any | BernoulliDistribution | Probability | Zero | One | Expr | Float | ComplexInfinity | Rational | NaN | NegativeOne | Integer | Half | Infinity | NegativeInfinity | _NotImplementedType | Self@Expr | tuple[Unknown, ...] | Sum | Order | Piecewise | Basic | Equality | Lambda | Number | Relational | Unequality | int | None)" (reportUnknownVariableType)
+     Type of "P" is "(condition: Unknown, given_condition: Unknown | None = None, numsamples: Unknown | None = None, evaluate: bool = True, **kwargs: Unknown) -> (Unknown | Any | BernoulliDistribution | Probability | Zero | One | Expr | Float | ComplexInfinity | Rational | NaN | NegativeOne | Integer | Half | Infinity | NegativeInfinity | _NotImplementedType | Self@Expr | tuple[Unknown, ...] | Sum | Order | Piecewise | Basic | Equality | Relational | Unequality | Lambda | Number | int | None)" (reportUnknownVariableType)
-     Type of "variance" is "(X: Unknown, condition: Unknown | None = None, **kwargs: Unknown) -> (VarianceMatrix | Variance | Unknown | Any | CentralMoment)" (reportUnknownVariableType)
+     Type of "variance" is "(X: Unknown, condition: Unknown | None = None, **kwargs: Unknown) -> (VarianceMatrix | Variance | Unknown | CentralMoment)" (reportUnknownVariableType)
-     Type of "skewness" is "(X: Unknown, condition: Unknown | None = None, **kwargs: Unknown) -> (Unknown | Any | Expr)" (reportUnknownVariableType)
+     Type of "skewness" is "(X: Unknown, condition: Unknown | None = None, **kwargs: Unknown) -> (Unknown | Expr)" (reportUnknownVariableType)
-     Type of "kurtosis" is "(X: Unknown, condition: Unknown | None = None, **kwargs: Unknown) -> (Unknown | Any | Expr)" (reportUnknownVariableType)
+     Type of "kurtosis" is "(X: Unknown, condition: Unknown | None = None, **kwargs: Unknown) -> (Unknown | Expr)" (reportUnknownVariableType)
-     Type of "moment" is "(X: Unknown, n: Unknown, c: int = 0, condition: Unknown | None = None, *, evaluate: bool = True, **kwargs: Unknown) -> (Unknown | Any | Moment)" (reportUnknownVariableType)
+     Type of "moment" is "(X: Unknown, n: Unknown, c: int = 0, condition: Unknown | None = None, *, evaluate: bool = True, **kwargs: Unknown) -> (Unknown | Moment)" (reportUnknownVariableType)
-     Type of "cmoment" is "(X: Unknown, n: Unknown, condition: Unknown | None = None, *, evaluate: bool = True, **kwargs: Unknown) -> (Unknown | Any | CentralMoment)" (reportUnknownVariableType)
+     Type of "cmoment" is "(X: Unknown, n: Unknown, condition: Unknown | None = None, *, evaluate: bool = True, **kwargs: Unknown) -> (Unknown | CentralMoment)" (reportUnknownVariableType)
-     Type of "doit" is "((**hints: Unknown) -> Equality) | Unknown | ((**hints: Unknown) -> Relational) | ((**hints: Unknown) -> Unequality) | ((**hints: Unknown) -> NaN) | ((**hints: Unknown) -> (tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Order | Any | Zero | NaN | Piecewise | Basic | None)) | ((**hints: Unknown) -> Unknown)" (reportUnknownMemberType)
+     Type of "doit" is "((**hints: Unknown) -> Equality) | Unknown | ((**hints: Unknown) -> Relational) | ((**hints: Unknown) -> Unequality) | ((**hints: Unknown) -> NaN) | ((**hints: Unknown) -> (tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Order | Any | Zero | NaN | Piecewise | Basic | Equality | Relational | Unequality | None)) | ((**hints: Unknown) -> Unknown)" (reportUnknownMemberType)
-     Type of "summation" is "(f: Unknown, ...) -> (tuple[Unknown, ...] | Unknown | Self@Sum | Self@Expr | Order | Any | Zero | NaN | Piecewise | Basic | Equality | Relational | Unequality | None)" (reportUnknownVariableType)
+     Type of "summation" is "(f: Unknown, ...) -> (tuple[Unknown, ...] | Unknown | Self@Sum | Self@Expr | Order | Any | Zero | NaN | Piecewise | Basic | Equality | Relational | Unequality | Sum | None)" (reportUnknownVariableType)
-     Type of "set" is "tuple[tuple[Dummy, _NotImplementedType | Unknown | Any]]" (reportUnknownVariableType)
+     Type of "set" is "tuple[tuple[Dummy, _NotImplementedType | LessThan | Unknown | Equality | Relational | Unequality | Any]]" (reportUnknownVariableType)
-     Type of "density" is "(expr: Unknown, condition: Unknown | None = None, evaluate: bool = True, numsamples: Unknown | None = None, **kwargs: Unknown) -> Unknown" (reportUnknownVariableType)
+     Type of "density" is "(expr: Unknown, condition: Unknown | None = None, evaluate: bool = True, numsamples: Unknown | None = None, **kwargs: Unknown) -> (dict[Unknown, Unknown] | Density | Lambda | Basic | Any | Unknown | FiniteDensity | None)" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:242:13 - warning: Type of "dens" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:242:13 - warning: Type of "dens" is partially unknown
+     Type of "dens" is "dict[Unknown, Unknown] | Density | Lambda | Basic | Any | Unknown | FiniteDensity | None" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:245:53 - warning: Argument type is unknown
-     Argument corresponds to parameter "pdf" in function "__new__" (reportUnknownArgumentType)

... (truncated 2578 lines) ...

cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stderr="error: branch '4e8031e9982a42390653aa7eb2bb45a235daab43' not found\n"
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stdout=''
pydantic (https://github.com/pydantic/pydantic): 1.50x slower (21.1s -> 31.8s in a single noisy sample)

cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stderr="error: branch '4e8031e9982a42390653aa7eb2bb45a235daab43' not found\n"
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stdout=''
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stderr="error: branch '4e8031e9982a42390653aa7eb2bb45a235daab43' not found\n"
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stdout=''
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stderr="error: branch '4e8031e9982a42390653aa7eb2bb45a235daab43' not found\n"
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stdout=''
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stderr="error: branch '4e8031e9982a42390653aa7eb2bb45a235daab43' not found\n"
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stdout=''
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stderr="error: branch '4e8031e9982a42390653aa7eb2bb45a235daab43' not found\n"
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stdout=''
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stderr="error: branch '4e8031e9982a42390653aa7eb2bb45a235daab43' not found\n"
cmd=['git', 'branch', '-D', '4e8031e9982a42390653aa7eb2bb45a235daab43'] stdout=''
arviz (https://github.com/arviz-devs/arviz): 3.64x slower (9.0s -> 32.9s in a single noisy sample)

@DetachHead DetachHead merged commit 0c3cdcf into main Nov 24, 2024
20 checks passed
@DetachHead DetachHead deleted the fix-generic-inlay-hints branch November 24, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

incorrect inlay hint for tuple type when it's nested inside another generic
1 participant