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

Implemented allowedUntypedLibraries config #970

Merged

Conversation

Wizzerinus
Copy link
Contributor

@Wizzerinus Wizzerinus commented Dec 27, 2024

Basically, this PR adds an allowedUntypedLibraries config field which is a list of strings (empty by default). If pyright cannot derive the type of a function, it normally gives an error (reportUnknownMemberType or reportUnknownVariableType), and if the library the method is implemented in is in this list, it doesn't, for example:

# both foo and bar are untyped, `allowedUntypedLibraries = ["first"]`
from first import foo
from second import bar
foo("123")   # ok
bar("456")   # error

Notes:

  • Not documented right now
  • maybe it's better to name this allowedUntypedModules instead of libraries
  • maybe it would be good to allow configuring a list of modules deeper than 1 level (i.e. "library is strongly typed but library.new_submodule isn't"), although I think this is not necessary due to the uses of this feature (the point is that the rule normally targets the code written for the project, and this PR targets the code written for a library used in the project, which are usually not intersecting)

resolves #701

This comment has been minimized.

Copy link
Owner

@DetachHead DetachHead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are probably other things we will need to consider as well that haven't yet crossed my mind

packages/pyright-internal/src/baseline.ts Outdated Show resolved Hide resolved
packages/pyright-internal/src/common/configOptions.ts Outdated Show resolved Hide resolved

This comment has been minimized.

@Wizzerinus Wizzerinus force-pushed the feature/config/allowed-untyped-libraries branch from 5b2c8f3 to 665bc94 Compare January 9, 2025 15:50
@Wizzerinus Wizzerinus force-pushed the feature/config/allowed-untyped-libraries branch from 665bc94 to e302c06 Compare January 9, 2025 15:53

This comment has been minimized.

docs/configuration.md Outdated Show resolved Hide resolved
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 "i" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "i" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "decompogen" is "(f: Unknown, symbol: Unknown) -> (list[Expr] | list[Function | Pow] | Unknown | list[Min | Max] | list[Expr | Unknown] | list[Unknown | Poly])" (reportUnknownVariableType)
+     Type of "decompogen" is "(f: Unknown, symbol: Unknown) -> (list[Expr] | list[Function | Pow] | Unknown | list[Min | Max] | list[Unknown] | list[Unknown | Poly])" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_decompogen.py:23:31 - warning: Return type of lambda, "list[Expr] | list[Function | Pow] | Unknown | list[Min | Max] | list[Expr | Unknown] | list[Unknown | Poly]", is partially unknown (reportUnknownLambdaType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_decompogen.py:23:31 - warning: Return type of lambda, "list[Expr] | list[Function | Pow] | Unknown | list[Min | Max] | list[Unknown] | list[Unknown | Poly]", is partially unknown (reportUnknownLambdaType)
-     Type of "rootof" is "(f: Unknown, x: Unknown, index: Unknown | None = None, radicals: bool = True, expand: bool = True) -> (Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Expr)" (reportUnknownVariableType)
+     Type of "rootof" is "(f: Unknown, x: Unknown, index: Unknown | None = None, radicals: bool = True, expand: bool = True) -> (Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType | Expr)" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_inequalities.py:134:9 - warning: Type of "inf" is partially unknown
-     Type of "inf" is "One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Unknown" (reportUnknownVariableType)
-     Argument type is "Equality | Unknown | Relational | Unequality" (reportUnknownArgumentType)
+     Argument type is "Equality | Unknown" (reportUnknownArgumentType)
-     Argument type is "Equality | Unknown | Relational | Unequality" (reportUnknownArgumentType)
+     Argument type is "Equality | Unknown" (reportUnknownArgumentType)
-     Type of "e" is "Equality | Unknown | Relational | Unequality | NaN | Sum" (reportUnknownVariableType)
+     Type of "e" is "Equality | Unknown | NaN | Sum" (reportUnknownVariableType)
-     Argument type is "Equality | Unknown | Relational | Unequality" (reportUnknownArgumentType)
+     Argument type is "Equality | Unknown" (reportUnknownArgumentType)
-     Argument type is "Equality | Unknown | Relational | Unequality" (reportUnknownArgumentType)
+     Argument type is "Equality | Unknown" (reportUnknownArgumentType)
-     Argument type is "Equality | Unknown | Relational | Unequality" (reportUnknownArgumentType)
+     Argument type is "Equality | Unknown" (reportUnknownArgumentType)
-     Argument type is "Equality | Unknown | Relational | Unequality" (reportUnknownArgumentType)
+     Argument type is "Equality | Unknown" (reportUnknownArgumentType)
-     Type of "r" is "Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Expr" (reportUnknownVariableType)
+     Type of "r" is "Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType | Expr" (reportUnknownVariableType)
-     Type of "ie" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "ie" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "e" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "e" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "eq" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "eq" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "eq" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "eq" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "eq" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "eq" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "wave" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "wave" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "eq" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "eq" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "eq" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "eq" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "sol4" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "sol4" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "expand" is "((**kwargs: Unknown) -> Equality) | Unknown | ((**kwargs: Unknown) -> Relational) | ((**kwargs: Unknown) -> Unequality)" (reportUnknownMemberType)
+     Type of "expand" is "((**kwargs: Unknown) -> Equality) | Unknown" (reportUnknownMemberType)
-     Type of "expand" is "((**kwargs: Unknown) -> Equality) | Unknown | ((**kwargs: Unknown) -> Relational) | ((**kwargs: Unknown) -> Unequality)" (reportUnknownMemberType)
+     Type of "expand" is "((**kwargs: Unknown) -> Equality) | Unknown" (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_recurr.py:116:5 - warning: Type of "h" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_recurr.py:116:5 - warning: Type of "h" is Any (reportAny)
-   /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], 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)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:105:13 - warning: Return type, "Integer | Unknown | NaN | Expr | One | NegativeOne | Zero | Rational | ComplexInfinity | Half", is partially unknown (reportUnknownParameterType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:109:20 - warning: Return type, "Unknown | NaN | Expr | One | NegativeOne | Zero | Integer | Rational | ComplexInfinity | Half", is partially unknown (reportUnknownVariableType)
-     Type of "constraints" is "list[_NotImplementedType | Unknown | Any | GreaterThan | Equality | Relational | Unequality]" (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:111:29 - warning: Argument type is partially unknown
-     Argument corresponds to parameter "iterable" in function "sum"
-     Argument type is "Generator[Any | Unknown, None, None]" (reportUnknownArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:113:25 - warning: Argument type is partially unknown
-     Argument corresponds to parameter "iterable" in function "sum"
-     Argument type is "Generator[Any | Unknown, None, None]" (reportUnknownArgumentType)
-   /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], 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 "r1" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "r1" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "r2" is "Equality | Unknown | Relational | Unequality" (reportUnknownVariableType)
+     Type of "r2" is "Equality | Unknown" (reportUnknownVariableType)
-     Type of "constraints" is "list[Equality | Unknown | Relational | Unequality | Any]" (reportUnknownVariableType)
+     Type of "constraints" is "list[Equality | Unknown | Any]" (reportUnknownVariableType)
-     Type of "constr" is "Equality | Unknown | Relational | Unequality | Any" (reportUnknownVariableType)
+     Type of "constr" is "Equality | Unknown | Any" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:181:5 - warning: Type of "ans" is partially unknown
-     Type of "ans" is "tuple[Unknown, list[int | Unknown]]" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:221:9 - warning: Type of "ans" is partially unknown
-     Type of "ans" is "tuple[Unknown, list[int | Unknown]]" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:222:48 - warning: Argument type is partially unknown
-     Argument corresponds to parameter "iterable" in function "__init__"
-     Argument type is "zip[tuple[Any, int | Unknown]]" (reportUnknownArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:222:55 - warning: Argument type is partially unknown
-     Argument corresponds to parameter "iter2" in function "__new__"

... (truncated 2673 lines) ...

dulwich (https://github.com/dulwich/dulwich): 2.92x slower (6.0s -> 17.6s in a single noisy sample)

@DetachHead DetachHead merged commit 1ae2564 into DetachHead:main Jan 14, 2025
16 checks passed
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.

Apply different typing rules to particular (external) packages
3 participants