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

add inlay hints for generics when instantiating classes #818

Merged
merged 6 commits into from
Oct 28, 2024

Conversation

DetachHead
Copy link
Owner

@DetachHead DetachHead commented Oct 27, 2024

  • maybe turn off this inlay hint type by default, because having inlay hints for both type annotations and generics often results in redundant information:
    image
  • add tests
  • i think tuple needs to be special cased
  • update docs (currently it says only Final and ClassVar are supported)
  • other ways generics can be specialized eg. class method calls (thats not a thing)

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

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

sympy (https://github.com/sympy/sympy)
-     Type of "sqrtdenest" is "(expr: Unknown, max_iter: int = 3) -> Unknown" (reportUnknownVariableType)
+     Type of "sqrtdenest" is "(expr: Unknown, max_iter: int = 3) -> (Unknown | Mul | Pow | Order | Expr | Add | None)" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/ode/subscheck.py:385:22 - warning: Type of "simplify" is partially unknown
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/ode/subscheck.py:385:22 - warning: Type of "simplify" is unknown (reportUnknownMemberType)
-     Type of "simplify" is "Unknown | ((**kwargs: Unknown) -> Unknown)" (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/ode/subscheck.py:385:37 - error: "simplify" is not a known attribute of "None" (reportOptionalMemberAccess)
-     Type of "_" is "Unknown | Any | Literal[False]" (reportUnknownVariableType)
+     Type of "_" is "Unknown | Literal[False]" (reportUnknownVariableType)
-     Type of "_" is "Unknown | Any | Literal[False]" (reportUnknownVariableType)
+     Type of "_" is "Unknown | Literal[False]" (reportUnknownVariableType)
-     Type of "_" is "Unknown | Any | Literal[False]" (reportUnknownVariableType)
+     Type of "_" is "Unknown | Literal[False]" (reportUnknownVariableType)
-     Type of "_" is "Unknown | Any | Literal[False]" (reportUnknownVariableType)
+     Type of "_" is "Unknown | Literal[False]" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:501:5 - warning: Type of "eqs" is partially unknown
+     Type of "eqs" is "list[Unknown]" (reportUnknownVariableType)
-     Argument type is "Unknown | Any | _NotImplementedType" (reportUnknownArgumentType)
+     Argument type is "Unknown | _NotImplementedType" (reportUnknownArgumentType)
-     Type of "eqs" is "list[Unknown | Any]" (reportUnknownVariableType)
+     Type of "eqs" is "list[Unknown]" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:505:16 - warning: Argument type is partially unknown
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:505:16 - warning: Argument type is unknown
-     Argument corresponds to parameter "iterable" in function "__init__"
+     Argument corresponds to parameter "iterable" in function "__init__" (reportUnknownArgumentType)
-     Argument type is "Unknown | Any" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:717:18 - warning: Argument type is unknown
+     Argument corresponds to parameter "f" in function "solve" (reportUnknownArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1768:5 - warning: Type of "eqs" is partially unknown
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1768:5 - warning: Type of "eqs" is unknown (reportUnknownVariableType)
-     Type of "eqs" is "Unknown | Any" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1769:18 - warning: Argument type is unknown
+     Argument corresponds to parameter "f" in function "solve" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1770:18 - warning: Argument type is unknown
+     Argument corresponds to parameter "f" in function "solve" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/tests/test_symbolic_multivariate.py:64:50 - warning: Argument type is unknown
+     Argument corresponds to parameter "expr" in function "__new__" (reportUnknownArgumentType)
-     Type of "c" is "Unknown | Any | _NotImplementedType" (reportUnknownVariableType)
+     Type of "c" is "Unknown | _NotImplementedType" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_lambdify.py:634:29 - warning: Argument type is unknown
+     Argument corresponds to parameter "expr" in function "lambdify" (reportUnknownArgumentType)
-     Type of "dot" is "(b: Unknown, hermitian: Unknown | None = None, conjugate_convention: Unknown | None = None) -> (Unknown | Any)" (reportUnknownMemberType)
+     Type of "dot" is "(b: Unknown, hermitian: Unknown | None = None, conjugate_convention: Unknown | None = None) -> Unknown" (reportUnknownMemberType)
+   /tmp/mypy_primer/projects/sympy/sympy/utilities/tests/test_wester.py:1313:24 - warning: Argument type is unknown
+     Argument corresponds to parameter "e" in function "expand" (reportUnknownArgumentType)
-     Type of "dot" is "(b: Unknown, hermitian: Unknown | None = None, conjugate_convention: Unknown | None = None) -> (Unknown | Any)" (reportUnknownMemberType)
+     Type of "dot" is "(b: Unknown, hermitian: Unknown | None = None, conjugate_convention: Unknown | None = None) -> Unknown" (reportUnknownMemberType)
+   /tmp/mypy_primer/projects/sympy/sympy/vector/coordsysrect.py:289:25 - warning: Argument type is unknown
+     Argument corresponds to parameter "expr" in function "simplify" (reportUnknownArgumentType)
-     Type of "dot" is "(b: Unknown, hermitian: Unknown | None = None, conjugate_convention: Unknown | None = None) -> (Unknown | Any)" (reportUnknownMemberType)
+     Type of "dot" is "(b: Unknown, hermitian: Unknown | None = None, conjugate_convention: Unknown | None = None) -> Unknown" (reportUnknownMemberType)
+   /tmp/mypy_primer/projects/sympy/sympy/vector/coordsysrect.py:289:55 - warning: Argument type is unknown
+     Argument corresponds to parameter "expr" in function "simplify" (reportUnknownArgumentType)
-     Type of "dot" is "(b: Unknown, hermitian: Unknown | None = None, conjugate_convention: Unknown | None = None) -> (Unknown | Any)" (reportUnknownMemberType)
+     Type of "dot" is "(b: Unknown, hermitian: Unknown | None = None, conjugate_convention: Unknown | None = None) -> Unknown" (reportUnknownMemberType)
+   /tmp/mypy_primer/projects/sympy/sympy/vector/coordsysrect.py:290:30 - warning: Argument type is unknown
+     Argument corresponds to parameter "expr" in function "simplify" (reportUnknownArgumentType)
- 87992 errors, 514598 warnings, 0 notes
+ 87991 errors, 514608 warnings, 0 notes

antidote (https://github.com/Finistere/antidote): 6.87x slower (2.7s -> 18.7s in a single noisy sample)

spack (https://github.com/spack/spack)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlite-jdbc/package.py:22:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlite-jdbc/package.py:22:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlitebrowser/package.py:22:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlitebrowser/package.py:22:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlitebrowser/package.py:23:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlitebrowser/package.py:23:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlitebrowser/package.py:33:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlitebrowser/package.py:33:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlitebrowser/package.py:34:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqlitebrowser/package.py:34:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqoop/package.py:24:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/sqoop/package.py:24:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:55:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:55:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:92:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:92:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:93:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:93:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:94:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:94:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:95:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:95:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:96:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:96:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:97:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:97:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:98:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:98:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:99:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:99:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:100:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs/package.py:100:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs-mount/package.py:23:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs-mount/package.py:23:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs-mount/package.py:27:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfs-mount/package.py:27:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
-   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfuse/package.py:34:5 - warning: Result of call expression is of type "((pkg: PackageBase) -> None)" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+   /tmp/mypy_primer/projects/spack/var/spack/repos/builtin/packages/squashfuse/package.py:34:5 - warning: Result of call expression is of type "(pkg: PackageBase) -> None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)

... (truncated 4298 lines) ...

@DetachHead DetachHead merged commit 8cde9f7 into main Oct 28, 2024
20 checks passed
@DetachHead DetachHead deleted the generic-inlay-hints branch October 28, 2024 13:03
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.

2 participants