Skip to content

Fix pyright narrowing issue#11367

Merged
gramster merged 2 commits intomicrosoft:mainfrom
gramster:fix-pyright-narrowing-issue
Apr 9, 2026
Merged

Fix pyright narrowing issue#11367
gramster merged 2 commits intomicrosoft:mainfrom
gramster:fix-pyright-narrowing-issue

Conversation

@gramster
Copy link
Copy Markdown
Member

@gramster gramster commented Apr 8, 2026

Any or Unknown will get narrowed to None after an "is None" check.

Fixes #10603

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

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

nionutils (https://github.com/nion-software/nionutils)
+   .../projects/nionutils/nion/utils/ListModel.py:661:56 - error: "item_changed_event" is not a known attribute of "None" (reportOptionalMemberAccess)
- 14 errors, 0 warnings, 0 informations
+ 15 errors, 0 warnings, 0 informations

pytest-autoprofile (https://gitlab.com/TTsangSC/pytest-autoprofile)
+   .../projects/pytest-autoprofile/src/pytest_autoprofile/plugin.py:163:12 - error: Type "Any | None" is not assignable to return type "int"
+     Type "Any | None" is not assignable to type "int"
+       "None" is not assignable to "int" (reportReturnType)
- 125 errors, 4 warnings, 0 informations
+ 126 errors, 4 warnings, 0 informations

ibis (https://github.com/ibis-project/ibis)
-   .../projects/ibis/ibis/backends/athena/__init__.py:225:57 - error: Argument of type "tuple[Unknown, Unknown]" cannot be assigned to parameter "database" of type "str | None" in function "table"
+   .../projects/ibis/ibis/backends/athena/__init__.py:225:57 - error: Argument of type "tuple[Unknown | None, Unknown | None]" cannot be assigned to parameter "database" of type "str | None" in function "table"
-     Type "tuple[Unknown, Unknown]" is not assignable to type "str | None"
+     Type "tuple[Unknown | None, Unknown | None]" is not assignable to type "str | None"
-       "tuple[Unknown, Unknown]" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "str"
-       "tuple[Unknown, Unknown]" is not assignable to "None" (reportArgumentType)
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "None" (reportArgumentType)
-   .../projects/ibis/ibis/backends/bigquery/__init__.py:1327:42 - error: Argument of type "tuple[Unknown, str | None]" cannot be assigned to parameter "database" of type "str | None" in function "table"
+   .../projects/ibis/ibis/backends/bigquery/__init__.py:1327:42 - error: Argument of type "tuple[Unknown | None, str | None]" cannot be assigned to parameter "database" of type "str | None" in function "table"
-     Type "tuple[Unknown, str | None]" is not assignable to type "str | None"
+     Type "tuple[Unknown | None, str | None]" is not assignable to type "str | None"
-       "tuple[Unknown, str | None]" is not assignable to "str"
+       "tuple[Unknown | None, str | None]" is not assignable to "str"
-       "tuple[Unknown, str | None]" is not assignable to "None" (reportArgumentType)
+       "tuple[Unknown | None, str | None]" is not assignable to "None" (reportArgumentType)
+   .../projects/ibis/ibis/backends/oracle/__init__.py:502:43 - error: Argument of type "tuple[Unknown | None, Unknown | None]" cannot be assigned to parameter "database" of type "tuple[str, str] | str | None" in function "drop_table"
+     Type "tuple[Unknown | None, Unknown | None]" is not assignable to type "tuple[str, str] | str | None"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "tuple[str, str]"
+         Tuple entry 1 is incorrect type
+           Type "Unknown | None" is not assignable to type "str"
+             "None" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "None" (reportArgumentType)
-     Return type mismatch: base method returns type "(value: Unknown, dtype: Unknown = dtype) -> (Unknown | Timestamp)", override returns type "(date_string: str) -> Timestamp"
+     Return type mismatch: base method returns type "(value: Unknown, dtype: Unknown = dtype) -> (Timestamp | Unknown | None)", override returns type "(date_string: str) -> Timestamp"
-       Type "(date_string: str) -> Timestamp" is not assignable to type "(value: Unknown, dtype: Unknown = dtype) -> (Unknown | Timestamp)"
+       Type "(date_string: str) -> Timestamp" is not assignable to type "(value: Unknown, dtype: Unknown = dtype) -> (Timestamp | Unknown | None)"
+   .../projects/ibis/ibis/backends/pyspark/__init__.py:699:42 - error: Argument of type "tuple[Unknown | None, Unknown | None]" cannot be assigned to parameter "database" of type "tuple[str, str] | str | None" in function "table"
+     Type "tuple[Unknown | None, Unknown | None]" is not assignable to type "tuple[str, str] | str | None"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "tuple[str, str]"
+         Tuple entry 1 is incorrect type
+           Type "Unknown | None" is not assignable to type "str"
+             "None" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "None" (reportArgumentType)
-     Return type mismatch: base method returns type "(value: Unknown, dtype: Unknown = dtype) -> (Unknown | Timestamp)", override returns type "(value: Unknown) -> Unknown"
+     Return type mismatch: base method returns type "(value: Unknown, dtype: Unknown = dtype) -> (Timestamp | Unknown | None)", override returns type "(value: Unknown) -> Unknown"
-       Type "(value: Unknown) -> Unknown" is not assignable to type "(value: Unknown, dtype: Unknown = dtype) -> (Unknown | Timestamp)"
+       Type "(value: Unknown) -> Unknown" is not assignable to type "(value: Unknown, dtype: Unknown = dtype) -> (Timestamp | Unknown | None)"
-     Return type mismatch: base method returns type "(value: Unknown, dtype: Unknown = dtype) -> (Unknown | Timestamp)", override returns type "(date_string: str) -> Timestamp"
+     Return type mismatch: base method returns type "(value: Unknown, dtype: Unknown = dtype) -> (Timestamp | Unknown | None)", override returns type "(date_string: str) -> Timestamp"
-       Type "(date_string: str) -> Timestamp" is not assignable to type "(value: Unknown, dtype: Unknown = dtype) -> (Unknown | Timestamp)"
+       Type "(date_string: str) -> Timestamp" is not assignable to type "(value: Unknown, dtype: Unknown = dtype) -> (Timestamp | Unknown | None)"
+   .../projects/ibis/ibis/backends/sql/__init__.py:253:42 - error: Argument of type "tuple[Unknown | None, Unknown | None]" cannot be assigned to parameter "database" of type "tuple[str, str] | str | None" in function "table"
+     Type "tuple[Unknown | None, Unknown | None]" is not assignable to type "tuple[str, str] | str | None"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "tuple[str, str]"
+         Tuple entry 1 is incorrect type
+           Type "Unknown | None" is not assignable to type "str"
+             "None" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "None" (reportArgumentType)
+   .../projects/ibis/ibis/backends/sql/__init__.py:453:48 - error: Argument of type "tuple[Unknown | None, Unknown | None]" cannot be assigned to parameter "database" of type "str | tuple[str, str] | None" in function "truncate_table"
+     Type "tuple[Unknown | None, Unknown | None]" is not assignable to type "str | tuple[str, str] | None"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "tuple[str, str]"
+         Tuple entry 1 is incorrect type
+           Type "Unknown | None" is not assignable to type "str"
+             "None" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "None" (reportArgumentType)
+   .../projects/ibis/ibis/backends/trino/__init__.py:514:57 - error: Argument of type "tuple[Unknown | None, Unknown | None]" cannot be assigned to parameter "database" of type "tuple[str, str] | str | None" in function "table"
+     Type "tuple[Unknown | None, Unknown | None]" is not assignable to type "tuple[str, str] | str | None"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "tuple[str, str]"
+         Tuple entry 1 is incorrect type
+           Type "Unknown | None" is not assignable to type "str"
+             "None" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "str"
+       "tuple[Unknown | None, Unknown | None]" is not assignable to "None" (reportArgumentType)
+   .../projects/ibis/ibis/expr/builders.py:258:26 - error: "None" is not iterable
+     "__iter__" method not defined (reportGeneralTypeIssues)
+   .../projects/ibis/ibis/expr/builders.py:270:26 - error: "None" is not iterable
+     "__iter__" method not defined (reportGeneralTypeIssues)
+   .../projects/ibis/ibis/expr/builders.py:283:36 - error: Argument of type "Unknown | None" cannot be assigned to parameter "value" of type "Value[T@WindowBoundary, S@WindowBoundary]" in function "__init__"
+     Type "Unknown | None" is not assignable to type "Value[T@WindowBoundary, S@WindowBoundary]"
+       "None" is not assignable to "Value[T@WindowBoundary, S@WindowBoundary]" (reportArgumentType)
+   .../projects/ibis/ibis/expr/builders.py:284:36 - error: Argument of type "Unknown | None" cannot be assigned to parameter "value" of type "Value[T@WindowBoundary, S@WindowBoundary]" in function "__init__"
+     Type "Unknown | None" is not assignable to type "Value[T@WindowBoundary, S@WindowBoundary]"
+       "None" is not assignable to "Value[T@WindowBoundary, S@WindowBoundary]" (reportArgumentType)
+   .../projects/ibis/ibis/expr/builders.py:289:43 - error: Argument of type "Unknown | None" cannot be assigned to parameter "value" of type "Value[T@WindowBoundary, S@WindowBoundary]" in function "__init__"
+     Type "Unknown | None" is not assignable to type "Value[T@WindowBoundary, S@WindowBoundary]"
+       "None" is not assignable to "Value[T@WindowBoundary, S@WindowBoundary]" (reportArgumentType)
+   .../projects/ibis/ibis/expr/builders.py:293:49 - error: Argument of type "Unknown | None" cannot be assigned to parameter "value" of type "Value[T@WindowBoundary, S@WindowBoundary]" in function "__init__"
+     Type "Unknown | None" is not assignable to type "Value[T@WindowBoundary, S@WindowBoundary]"
+       "None" is not assignable to "Value[T@WindowBoundary, S@WindowBoundary]" (reportArgumentType)
-   .../projects/ibis/ibis/expr/types/strings.py:110:42 - error: Argument of type "Any | Expr" cannot be assigned to parameter "start" of type "Value[Integer, Any] | None" in function "__init__"
+   .../projects/ibis/ibis/expr/types/strings.py:110:42 - error: Argument of type "Expr | Any | None" cannot be assigned to parameter "start" of type "Value[Integer, Any] | None" in function "__init__"
-     Type "Any | Expr" is not assignable to type "Value[Integer, Any] | None"

... (truncated 7 lines) ...

sympy (https://github.com/sympy/sympy)
+   .../projects/sympy/sympy/core/expr.py:1009:14 - error: "is_comparable" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/core/function.py:1032:32 - error: Object of type "None" cannot be used as iterable value (reportOptionalIterable)
-     Return type mismatch: base method returns type "None", override returns type "ReciprocalHyperbolicFunction | Expr | Unknown"
+     Return type mismatch: base method returns type "None", override returns type "ReciprocalHyperbolicFunction | Expr | Unknown | None"
-       Type "ReciprocalHyperbolicFunction | Expr | Unknown" is not assignable to type "None"
+       Type "ReciprocalHyperbolicFunction | Expr | Unknown | None" is not assignable to type "None"
-     Return type mismatch: base method returns type "None", override returns type "ReciprocalTrigonometricFunction | Expr | Unknown"
+     Return type mismatch: base method returns type "None", override returns type "ReciprocalTrigonometricFunction | Expr | Unknown | None"
-       Type "ReciprocalTrigonometricFunction | Expr | Unknown" is not assignable to type "None"
+       Type "ReciprocalTrigonometricFunction | Expr | Unknown | None" is not assignable to type "None"
+   .../projects/sympy/sympy/functions/elementary/trigonometric.py:1719:17 - error: Operator "-" not supported for "None" (reportOptionalOperand)
+   .../projects/sympy/sympy/logic/tests/test_inference.py:405:19 - error: "z3types" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/ntheory/residue_ntheory.py:1648:12 - error: "None" is not iterable
+     "__iter__" method not defined (reportGeneralTypeIssues)
+   .../projects/sympy/sympy/ntheory/residue_ntheory.py:1910:12 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+ .../projects/sympy/sympy/ntheory/tests/test_modular.py
+   .../projects/sympy/sympy/ntheory/tests/test_modular.py:8:16 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+   .../projects/sympy/sympy/polys/modulargcd.py:151:21 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+   .../projects/sympy/sympy/polys/modulargcd.py:622:27 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:230:28 - error: "rand" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:234:18 - error: "allclose" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:245:24 - error: "tensor" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:245:61 - error: "float64" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:246:18 - error: "allclose" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:277:24 - error: "tensor" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:277:61 - error: "float64" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:280:22 - error: "linalg" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/printing/tests/test_torch.py:281:18 - error: "allclose" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/sympy/sympy/series/formal.py:778:19 - error: "free_symbols" is not a known attribute of "None" (reportOptionalMemberAccess)
-   .../projects/sympy/sympy/solvers/ode/hypergeometric.py:247:67 - error: Operator "**" not supported for types "Basic" and "Literal[2]" (reportOperatorIssue)
+   .../projects/sympy/sympy/solvers/ode/lie_group.py:619:61 - error: Operator "-" not supported for type "Unknown | Basic" (reportOperatorIssue)
-   .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:468:28 - error: Argument of type "Expr | Unknown | None" cannot be assigned to parameter "expr" of type "Expr" in function "make_args"
+   .../projects/sympy/sympy/solvers/ode/nonhomogeneous.py:468:28 - error: Argument of type "Unknown | None" cannot be assigned to parameter "expr" of type "Expr" in function "make_args"
-     Type "Expr | Unknown | None" is not assignable to type "Expr"
+     Type "Unknown | None" is not assignable to type "Expr"
+     Attribute "pop" is unknown (reportAttributeAccessIssue)
+   .../projects/sympy/sympy/solvers/ode/ode.py:610:22 - error: Cannot access attribute "pop" for class "tuple[()]"
+     Attribute "pop" is unknown (reportAttributeAccessIssue)
+   .../projects/sympy/sympy/solvers/ode/ode.py:610:22 - error: Cannot access attribute "pop" for class "tuple[str, ...]"
-   .../projects/sympy/sympy/solvers/ode/single.py:867:9 - error: Expression with type "tuple[ComplexInfinity | Unknown | Any, list[tuple[Unknown, Unknown]] | list[Unknown]] | tuple[ComplexInfinity | Unknown | Any, list[tuple[Unknown, Unknown]] | list[Unknown], list[tuple[Unknown, Unknown]] | list[Unknown]]" cannot be assigned to target tuple
-     Type "tuple[ComplexInfinity | Unknown | Any, list[tuple[Unknown, Unknown]] | list[Unknown], list[tuple[Unknown, Unknown]] | list[Unknown]]" is incompatible with target tuple
-       Tuple size mismatch; expected 2 but received 3 (reportAssignmentType)
+   .../projects/sympy/sympy/solvers/ode/single.py:2646:27 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr | Unknown | int" cannot be assigned to parameter "stop" of type "SupportsIndex" in function "__new__"
+     Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr | Unknown | int" is not assignable to type "SupportsIndex"
+       "Expr" is incompatible with protocol "SupportsIndex"
+         "__index__" is not present (reportArgumentType)
-   .../projects/sympy/sympy/solvers/ode/single.py:2652:9 - error: Operator "+=" not supported for types "Unknown | Any | Zero | One | NegativeOne | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" and "Basic | Any | Unknown"
+   .../projects/sympy/sympy/solvers/ode/single.py:2652:9 - error: Operator "+=" not supported for types "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr | Any | Unknown" and "Basic | Any | Unknown"
-   .../projects/sympy/sympy/solvers/ode/systems.py:1214:26 - error: Argument of type "dict[str, str | Unknown | Expr | bool | Symbol]" cannot be assigned to parameter "m" of type "Iterable[tuple[str, str]]" in function "update"
+   .../projects/sympy/sympy/solvers/ode/systems.py:1214:26 - error: Argument of type "dict[str, str | Unknown | Pow | bool | Symbol]" cannot be assigned to parameter "m" of type "Iterable[tuple[str, str]]" in function "update"
-   .../projects/sympy/sympy/stats/crv_types.py:2543:9 - error: Method "_cdf" overrides class "SingleContinuousDistribution" in an incompatible manner
-     Return type mismatch: base method returns type "None", override returns type "ComplexInfinity | Unknown"
-       Type "ComplexInfinity | Unknown" is not assignable to type "None"
-         "ComplexInfinity" is not assignable to "None" (reportIncompatibleMethodOverride)
-   .../projects/sympy/sympy/stats/crv_types.py:2722:9 - error: Method "_cdf" overrides class "SingleContinuousDistribution" in an incompatible manner
-     Return type mismatch: base method returns type "None", override returns type "Expr | Unknown"
-       Type "Expr | Unknown" is not assignable to type "None"
-         "Expr" is not assignable to "None" (reportIncompatibleMethodOverride)
-   .../projects/sympy/sympy/stats/symbolic_probability.py:75:9 - error: Method "doit" overrides class "Basic" in an incompatible manner
-     Return type mismatch: base method returns type "Basic", override returns type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]"
-       Type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" is not assignable to type "Basic"
-         "Literal[0]" is not assignable to "Basic" (reportIncompatibleMethodOverride)
-   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1543:12 - error: No overloads for "simplify" match the provided arguments (reportCallIssue)
-   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1543:21 - error: Argument of type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
-     Type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" is not assignable to type "Basic"
-       "Literal[0]" is not assignable to "Basic" (reportArgumentType)

... (truncated 1165 lines) ...

urllib3 (https://github.com/urllib3/urllib3)
+ .../projects/urllib3/test/contrib/emscripten/conftest.py
+   .../projects/urllib3/test/contrib/emscripten/conftest.py:32:42 - error: Argument of type "Any | None" cannot be assigned to parameter "args" of type "StrPath" in function "__new__"
+     Type "Any | None" is not assignable to type "StrPath"
+       Type "None" is not assignable to type "StrPath"
+         "None" is not assignable to "str"
+         "None" is incompatible with protocol "PathLike[str]"
+           "__fspath__" is not present (reportArgumentType)
+   .../projects/urllib3/test/contrib/emscripten/conftest.py:328:51 - error: "startswith" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/urllib3/test/contrib/emscripten/conftest.py:336:53 - error: "startswith" is not a known attribute of "None" (reportOptionalMemberAccess)
- 154 errors, 14 warnings, 0 informations
+ 157 errors, 14 warnings, 0 informations

pytest (https://github.com/pytest-dev/pytest)
+   .../projects/pytest/src/_pytest/debugging.py:144:32 - error: Cannot assign to attribute "_wrapped_pdb_cls" for class "type[pytestPDB]*"
+     Type "tuple[Any | None, type[PytestPdbWrapper]]" is not assignable to type "tuple[type[Any], type[Any]] | None"
+       "tuple[Any | None, type[PytestPdbWrapper]]" is not assignable to "tuple[type[Any], type[Any]]"
+         Tuple entry 1 is incorrect type
+           Type "Any | None" is not assignable to type "type[Any]"
+             "None" is not assignable to "type[Any]"
+       "tuple[Any | None, type[PytestPdbWrapper]]" is not assignable to "None" (reportAttributeAccessIssue)
+   .../projects/pytest/src/_pytest/doctest.py:349:48 - error: Argument of type "Any | None" cannot be assigned to parameter "key" of type "str" in function "_get_report_choice"
+     Type "Any | None" is not assignable to type "str"
+       "None" is not assignable to "str" (reportArgumentType)
+   .../projects/pytest/src/_pytest/doctest.py:411:33 - error: Type "Any | None" is not assignable to declared type "bool"
+     Type "Any | None" is not assignable to type "bool"
+       "None" is not assignable to "bool" (reportAssignmentType)
+ .../projects/pytest/src/_pytest/nodes.py
+   .../projects/pytest/src/_pytest/nodes.py:451:24 - error: Argument of type "Any | None" cannot be assigned to parameter "showlocals" of type "bool" in function "getrepr"
+     Type "Any | None" is not assignable to type "bool"
+       "None" is not assignable to "bool" (reportArgumentType)
+   .../projects/pytest/src/_pytest/python.py:509:18 - error: Argument of type "Any | None" cannot be assigned to parameter "mode" of type "str | ImportMode" in function "import_path"
+     Type "Any | None" is not assignable to type "str | ImportMode"
+       Type "None" is not assignable to type "str | ImportMode"
+         "None" is not assignable to "str"
+         "None" is not assignable to "ImportMode" (reportArgumentType)
+ .../projects/pytest/src/_pytest/runner.py
+   .../projects/pytest/src/_pytest/runner.py:394:17 - error: Argument of type "Any | None" cannot be assigned to parameter "importmode" of type "str | ImportMode" in function "_loadconftestmodules"
+     Type "Any | None" is not assignable to type "str | ImportMode"
+       Type "None" is not assignable to type "str | ImportMode"
+         "None" is not assignable to "str"
+         "None" is not assignable to "ImportMode" (reportArgumentType)
+ .../projects/pytest/src/_pytest/stepwise.py
+   .../projects/pytest/src/_pytest/stepwise.py:106:27 - error: Cannot assign to attribute "skip" for class "StepwisePlugin*"
+     Type "Any | None" is not assignable to type "bool"
+       "None" is not assignable to "bool" (reportAttributeAccessIssue)
+   .../projects/pytest/src/_pytest/stepwise.py:107:28 - error: Cannot assign to attribute "reset" for class "StepwisePlugin*"
+     Type "Any | None" is not assignable to type "bool"
+       "None" is not assignable to "bool" (reportAttributeAccessIssue)
- 331 errors, 17 warnings, 0 informations
+ 339 errors, 17 warnings, 0 informations

stone (https://github.com/dropbox/stone)
+   .../projects/stone/stone/backends/python_client.py:197:40 - error: "get" is not a known attribute of "None" (reportOptionalMemberAccess)
- 1603 errors, 5 warnings, 0 informations
+ 1604 errors, 5 warnings, 0 informations

scikit-learn (https://github.com/scikit-learn/scikit-learn)
+   .../projects/scikit-learn/sklearn/calibration.py:376:56 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+   .../projects/scikit-learn/sklearn/cross_decomposition/_pls.py:1040:16 - error: "T" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/scikit-learn/sklearn/cross_decomposition/_pls.py:1044:48 - error: "shape" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/scikit-learn/sklearn/cross_decomposition/_pls.py:1069:31 - error: Argument of type "Unknown | None" cannot be assigned to parameter "b" of type "ArrayLike" in function "dot"
+     Type "Unknown | None" is not assignable to type "ArrayLike"
+       Type "None" is not assignable to type "ArrayLike"
+         "None" is incompatible with protocol "_Buffer"
+           "__buffer__" is not present
+         "None" is incompatible with protocol "_SupportsArray[dtype[Any]]"
+           "__array__" is not present
+         "None" is incompatible with protocol "_NestedSequence[_SupportsArray[dtype[Any]]]"
+           "__len__" is not present
+     ... (reportArgumentType)
+   .../projects/scikit-learn/sklearn/decomposition/_dict_learning.py:584:16 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+   .../projects/scikit-learn/sklearn/decomposition/_dict_learning.py:587:42 - error: Argument of type "NDArray[Unknown] | Unknown | None" cannot be assigned to parameter "obj" of type "Sized" in function "len"
+     Type "NDArray[Unknown] | Unknown | None" is not assignable to type "Sized"
+       "None" is incompatible with protocol "Sized"
+         "__len__" is not present (reportArgumentType)
+   .../projects/scikit-learn/sklearn/decomposition/_kernel_pca.py:378:30 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+   .../projects/scikit-learn/sklearn/decomposition/_kernel_pca.py:510:39 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+   .../projects/scikit-learn/sklearn/decomposition/_pca.py:683:39 - error: Object of type "None" is not subscriptable (reportOptionalSubscript)
+   .../projects/scikit-learn/sklearn/decomposition/_sparse_pca.py:332:33 - error: "T" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/scikit-learn/sklearn/decomposition/_truncated_svd.py:262:65 - error: "T" is not a known attribute of "None" (reportOptionalMemberAccess)
-   .../projects/scikit-learn/sklearn/decomposition/_truncated_svd.py:264:29 - error: Operator "*" not supported for types "Any | Unknown | Unbound" and "ndarray[_AnyShape, dtype[float32 | float64]] | Any | Unknown | Unbound"
+   .../projects/scikit-learn/sklearn/decomposition/_truncated_svd.py:264:29 - error: Operator "*" not supported for types "Any | Unknown | Unbound | None" and "ndarray[_AnyShape, dtype[float32 | float64]] | Any | Unknown | Unbound"
+     Operator "*" not supported for types "None" and "ndarray[_AnyShape, dtype[float32 | float64]]"
+     Operator "*" not supported for types "None" and "Unbound"
+   .../projects/scikit-learn/sklearn/decomposition/_truncated_svd.py:293:52 - error: "T" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/scikit-learn/sklearn/decomposition/_truncated_svd.py:311:26 - error: Argument of type "Any | Unknown | None" cannot be assigned to parameter "b" of type "ArrayLike" in function "dot"
+     Type "Any | Unknown | None" is not assignable to type "ArrayLike"
+       Type "None" is not assignable to type "ArrayLike"
+         "None" is incompatible with protocol "_Buffer"
+           "__buffer__" is not present
+         "None" is incompatible with protocol "_SupportsArray[dtype[Any]]"
+           "__array__" is not present
+         "None" is incompatible with protocol "_NestedSequence[_SupportsArray[dtype[Any]]]"
+           "__len__" is not present
+     ... (reportArgumentType)
+   .../projects/scikit-learn/sklearn/decomposition/_truncated_svd.py:322:33 - error: "shape" is not a known attribute of "None" (reportOptionalMemberAccess)
+   .../projects/scikit-learn/sklearn/decomposition/tests/test_incremental_pca.py:254:21 - error: Argument of type "Unknown | Any | None" cannot be assigned to parameter "actual" of type "_NumericArrayLike" in function "assert_allclose"
+     Type "Unknown | Any | None" is not assignable to type "_NumericArrayLike"
+       Type "None" is not assignable to type "_NumericArrayLike"
+         "None" is incompatible with protocol "_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]]"
+           "__array__" is not present
+         "None" is incompatible with protocol "_NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]]]"
+           "__len__" is not present
+           "__getitem__" is not present
+           "__contains__" is not present

... (truncated 540 lines) ...```

@gramster gramster requested review from heejaechang and rchiodo April 8, 2026 21:26
Copy link
Copy Markdown
Collaborator

@rchiodo rchiodo left a comment

Choose a reason for hiding this comment

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

Approved via Review Center.

@gramster gramster merged commit 81b8686 into microsoft:main Apr 9, 2026
16 checks passed
@gramster gramster deleted the fix-pyright-narrowing-issue branch April 9, 2026 16:51
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.

Failing to narrow Any to None

3 participants