Skip to content

[ty] Allow discovering dependencies in system Python environments#22994

Merged
carljm merged 1 commit intomainfrom
claude/fix-issue-2068-x2E5Q
Feb 12, 2026
Merged

[ty] Allow discovering dependencies in system Python environments#22994
carljm merged 1 commit intomainfrom
claude/fix-issue-2068-x2E5Q

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented Jan 31, 2026

Summary

Fixes astral-sh/ty#2068.

This change allows ty to discover and use dependencies installed in system Python environments where ty itself is installed.

The subtlety here is in the case where we discover a local .venv AND ty is installed in a different Python env. In this case, we prioritize the local .venv, to avoid false-negatives due to accidental reliance on globally installed packages.

Test Plan

Added test; existing tests continue to pass.

@carljm carljm added the ty Multi-file analysis & type inference label Jan 31, 2026
@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 31, 2026

Typing conformance results

No changes detected ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Jan 31, 2026

mypy_primer results

Changes were detected when running on open source projects
spack (https://github.com/spack/spack)
- lib/spack/spack/detection/path.py:169:33: error[invalid-argument-type] Argument to function `dedupe_paths` is incorrect: Expected `list[str]`, found `Unknown | list[int | str | bytes | ... omitted 3 union elements]`
+ lib/spack/spack/detection/path.py:169:33: error[invalid-argument-type] Argument to function `dedupe_paths` is incorrect: Expected `list[str]`, found `Unknown | list[int | bytes | PathLike[str] | ... omitted 3 union elements]`

pylox (https://github.com/sco1/pylox)
- pylox/containers/array.py:146:9: error[invalid-assignment] Object of type `deque[None | Unknown]` is not assignable to attribute `fields` of type `dict[Unknown, Unknown]`
+ pylox/containers/array.py:146:9: error[invalid-assignment] Object of type `deque[Unknown | None]` is not assignable to attribute `fields` of type `dict[Unknown, Unknown]`

meson (https://github.com/mesonbuild/meson)
- mesonbuild/dependencies/cuda.py:137:76: error[invalid-argument-type] Argument to function `version_compare_many` is incorrect: Expected `str`, found `Unknown | str | None`
+ mesonbuild/dependencies/cuda.py:137:76: error[invalid-argument-type] Argument to function `version_compare_many` is incorrect: Expected `str`, found `str | None | Unknown`

dd-trace-py (https://github.com/DataDog/dd-trace-py)
- tests/tracer/test_span.py:193:29: error[invalid-argument-type] Argument to bound method `set_metric` is incorrect: Expected `int | float`, found `str | Unknown | None | ... omitted 6 union elements`
+ tests/tracer/test_span.py:193:29: error[invalid-argument-type] Argument to bound method `set_metric` is incorrect: Expected `int | float`, found `int | Unknown | None | ... omitted 6 union elements`

ibis (https://github.com/ibis-project/ibis)
- ibis/selectors.py:333:16: error[invalid-return-type] Return type does not match returned value: expected `frozenset[str]`, found `frozenset[str | Buffer | Unknown]`
+ ibis/selectors.py:333:16: error[invalid-return-type] Return type does not match returned value: expected `frozenset[str]`, found `frozenset[Unknown | str | Buffer]`
- ibis/selectors.py:428:13: error[invalid-assignment] Object of type `frozenset[str | Unknown]` is not assignable to `tuple[str | Column, ...]`
+ ibis/selectors.py:428:13: error[invalid-assignment] Object of type `frozenset[Unknown | str]` is not assignable to `tuple[str | Column, ...]`

sympy (https://github.com/sympy/sympy)
- sympy/geometry/tests/test_util.py:128:55: error[invalid-argument-type] Argument to function `subsets` is incorrect: Expected `Sequence[Unknown]`, found `set[Unknown | Point2D]`
+ sympy/geometry/tests/test_util.py:128:55: error[invalid-argument-type] Argument to function `subsets` is incorrect: Expected `Sequence[Unknown]`, found `set[Point2D | Unknown]`
- sympy/integrals/prde.py:89:11: warning[possibly-missing-attribute] Attribute `as_poly` may be missing on object of type `Unknown | int`
+ sympy/integrals/prde.py:89:11: warning[possibly-missing-attribute] Attribute `as_poly` may be missing on object of type `int | Unknown`
- sympy/integrals/prde.py:89:61: warning[possibly-missing-attribute] Attribute `as_poly` may be missing on object of type `Unknown | int`
+ sympy/integrals/prde.py:89:61: warning[possibly-missing-attribute] Attribute `as_poly` may be missing on object of type `int | Unknown`
- sympy/integrals/prde.py:90:10: warning[possibly-missing-attribute] Attribute `as_poly` may be missing on object of type `Unknown | int`
+ sympy/integrals/prde.py:90:10: warning[possibly-missing-attribute] Attribute `as_poly` may be missing on object of type `int | Unknown`
- sympy/matrices/expressions/hadamard.py:81:22: error[invalid-argument-type] Argument to function `validate_matadd_integer` is incorrect: Expected `MatrixExpr`, found `int | Any | Basic | float | complex`
+ sympy/matrices/expressions/hadamard.py:81:22: error[invalid-argument-type] Argument to function `validate_matadd_integer` is incorrect: Expected `MatrixExpr`, found `Any | Basic | int | float | complex`
- sympy/matrices/expressions/kronecker.py:109:16: warning[possibly-missing-attribute] Attribute `is_Identity` may be missing on object of type `int | Any | Basic | float | complex`
+ sympy/matrices/expressions/kronecker.py:109:16: warning[possibly-missing-attribute] Attribute `is_Identity` may be missing on object of type `Any | Basic | int | float | complex`
- sympy/matrices/expressions/kronecker.py:110:33: warning[possibly-missing-attribute] Attribute `rows` may be missing on object of type `int | Any | Basic | float | complex`
+ sympy/matrices/expressions/kronecker.py:110:33: warning[possibly-missing-attribute] Attribute `rows` may be missing on object of type `Any | Basic | int | float | complex`
- sympy/matrices/expressions/matadd.py:60:22: error[invalid-argument-type] Argument to function `validate_matadd_integer` is incorrect: Expected `MatrixExpr`, found `Unknown | int | Basic | float | complex`
+ sympy/matrices/expressions/matadd.py:60:22: error[invalid-argument-type] Argument to function `validate_matadd_integer` is incorrect: Expected `MatrixExpr`, found `Unknown | Basic | int | float | complex`
- sympy/parsing/mathematica.py:692:38: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Never]`, found `Unknown | list[Unknown | str]`
- sympy/polys/fields.py:101:24: warning[possibly-missing-attribute] Attribute `as_numer_denom` may be missing on object of type `int | Any | Basic | float | complex`
+ sympy/polys/fields.py:101:24: warning[possibly-missing-attribute] Attribute `as_numer_denom` may be missing on object of type `Any | Basic | int | float | complex`
- sympy/polys/polyoptions.py:472:61: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `int | Any | Basic | float | complex`
+ sympy/polys/polyoptions.py:472:61: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `Any | Basic | int | float | complex`
- sympy/polys/polyoptions.py:474:61: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `int | Any | Basic | float | complex`
+ sympy/polys/polyoptions.py:474:61: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `Any | Basic | int | float | complex`
- sympy/polys/polyoptions.py:476:61: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `int | Any | Basic | float | complex`
+ sympy/polys/polyoptions.py:476:61: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `Any | Basic | int | float | complex`
- sympy/polys/polyoptions.py:478:63: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `int | Any | Basic | float | complex`
+ sympy/polys/polyoptions.py:478:63: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `Any | Basic | int | float | complex`
- sympy/polys/polyoptions.py:480:63: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `int | Any | Basic | float | complex`
+ sympy/polys/polyoptions.py:480:63: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `Any | Basic | int | float | complex`
- sympy/polys/polyoptions.py:482:61: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `int | Any | Basic | float | complex`
+ sympy/polys/polyoptions.py:482:61: error[invalid-argument-type] Argument to bound method `poly_ring` is incorrect: Expected `str | Expr`, found `Any | Basic | int | float | complex`
- sympy/polys/polyoptions.py:492:62: error[invalid-argument-type] Argument to bound method `frac_field` is incorrect: Expected `str | Expr`, found `int | Any | Basic | float | complex`
+ sympy/polys/polyoptions.py:492:62: error[invalid-argument-type] Argument to bound method `frac_field` is incorrect: Expected `str | Expr`, found `Any | Basic | int | float | complex`
- sympy/polys/polyoptions.py:494:62: error[invalid-argument-type] Argument to bound method `frac_field` is incorrect: Expected `str | Expr`, found `int | Any | Basic | float | complex`
+ sympy/polys/polyoptions.py:494:62: error[invalid-argument-type] Argument to bound method `frac_field` is incorrect: Expected `str | Expr`, found `Any | Basic | int | float | complex`
- sympy/series/order.py:153:20: warning[possibly-missing-attribute] Attribute `is_symbol` may be missing on object of type `Unknown | int | Basic | float | complex`
+ sympy/series/order.py:153:20: warning[possibly-missing-attribute] Attribute `is_symbol` may be missing on object of type `Unknown | Basic | int | float | complex`
- sympy/series/order.py:188:28: error[unsupported-operator] Operator `/` is not supported between objects of type `Literal[1]` and `Unknown | int | Basic | float | complex`
+ sympy/series/order.py:188:28: error[unsupported-operator] Operator `/` is not supported between objects of type `Literal[1]` and `Unknown | Basic | int | float | complex`
- sympy/series/order.py:192:29: error[unsupported-operator] Operator `/` is not supported between objects of type `Literal[-1]` and `Unknown | int | Basic | float | complex`
+ sympy/series/order.py:192:29: error[unsupported-operator] Operator `/` is not supported between objects of type `Literal[-1]` and `Unknown | Basic | int | float | complex`
- sympy/series/order.py:269:52: error[invalid-argument-type] Argument to bound method `as_independent` is incorrect: Expected `Basic | type[Basic]`, found `int | Any | Basic | float | complex`
+ sympy/series/order.py:269:52: error[invalid-argument-type] Argument to bound method `as_independent` is incorrect: Expected `Basic | type[Basic]`, found `Any | Basic | int | float | complex`
- sympy/series/order.py:269:52: error[invalid-argument-type] Argument to bound method `as_independent` is incorrect: Expected `Basic | type[Basic]`, found `int | Any | Basic | float | complex`
+ sympy/series/order.py:269:52: error[invalid-argument-type] Argument to bound method `as_independent` is incorrect: Expected `Basic | type[Basic]`, found `Any | Basic | int | float | complex`
- sympy/series/order.py:287:45: error[unsupported-operator] Unary operator `-` is not supported for object of type `int | Any | Basic | float | complex`
+ sympy/series/order.py:287:45: error[unsupported-operator] Unary operator `-` is not supported for object of type `Any | Basic | int | float | complex`
- sympy/series/order.py:288:48: error[unsupported-operator] Operator `**` is not supported between objects of type `int | Any | Basic | float | complex` and `Basic`
+ sympy/series/order.py:288:48: error[unsupported-operator] Operator `**` is not supported between objects of type `Any | Basic | int | float | complex` and `Basic`
- sympy/series/order.py:291:49: error[unsupported-operator] Unary operator `-` is not supported for object of type `int | Any | Basic | float | complex`
+ sympy/series/order.py:291:49: error[unsupported-operator] Unary operator `-` is not supported for object of type `Any | Basic | int | float | complex`
- sympy/series/order.py:297:53: error[unsupported-operator] Unary operator `-` is not supported for object of type `int | Any | Basic | float | complex`
+ sympy/series/order.py:297:53: error[unsupported-operator] Unary operator `-` is not supported for object of type `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1046:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1046:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1047:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1047:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1048:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1048:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1087:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1087:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1088:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1088:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1089:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1089:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1175:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1175:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1176:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1176:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1177:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1177:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1178:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1178:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1179:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1179:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1213:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1213:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1214:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1214:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1215:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1215:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1216:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1216:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1217:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1217:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1265:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1265:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1266:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1266:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1267:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1267:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1268:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1268:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1269:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1269:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1313:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1313:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1314:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1314:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1315:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1315:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1316:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1316:19: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Iterable[Unknown]`, found `Any | Basic | int | float | complex`
- sympy/simplify/hyperexpand.py:1317:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `int | Any | Basic | float | complex`
+ sympy/simplify/hyperexpand.py:1317:21: error[invalid-argument-type] Argument to bound method `pop` is incorrect: Expected `SupportsIndex`, found `Any | Basic | int | float | complex`
- sympy/simplify/simplify.py:357:10: error[unsupported-operator] Operator `/` is not supported between two objects of type `int | Any | Basic | float | complex`
+ sympy/simplify/simplify.py:357:10: error[unsupported-operator] Operator `/` is not supported between two objects of type `Any | Basic | int | float | complex`
- sympy/solvers/recurr.py:417:9: warning[possibly-missing-attribute] Attribute `subs` may be missing on object of type `int | Any | Basic | float | complex`
+ sympy/solvers/recurr.py:417:9: warning[possibly-missing-attribute] Attribute `subs` may be missing on object of type `Any | Basic | int | float | complex`
- sympy/solvers/recurr.py:421:24: warning[possibly-missing-attribute] Attribute `subs` may be missing on object of type `int | Any | Basic | float | complex`
+ sympy/solvers/recurr.py:421:24: warning[possibly-missing-attribute] Attribute `subs` may be missing on object of type `Any | Basic | int | float | complex`
- sympy/solvers/recurr.py:436:24: warning[possibly-missing-attribute] Attribute `subs` may be missing on object of type `int | Any | Basic | float | complex`
+ sympy/solvers/recurr.py:436:24: warning[possibly-missing-attribute] Attribute `subs` may be missing on object of type `Any | Basic | int | float | complex`
- sympy/solvers/recurr.py:589:23: warning[possibly-missing-attribute] Attribute `subs` may be missing on object of type `int | Any | Basic | float | complex`
+ sympy/solvers/recurr.py:589:23: warning[possibly-missing-attribute] Attribute `subs` may be missing on object of type `Any | Basic | int | float | complex`
- sympy/tensor/indexed.py:161:79: warning[possibly-missing-attribute] Attribute `is_number` may be missing on object of type `int | Any | Basic | float | complex`
+ sympy/tensor/indexed.py:161:79: warning[possibly-missing-attribute] Attribute `is_number` may be missing on object of type `Any | Basic | int | float | complex`
- sympy/tensor/indexed.py:169:39: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Basic`, found `int | Any | Basic | float | complex`
+ sympy/tensor/indexed.py:169:39: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Basic`, found `Any | Basic | int | float | complex`
- sympy/tensor/indexed.py:650:12: warning[possibly-missing-attribute] Attribute `is_Number` may be missing on object of type `None | Any | Basic | ... omitted 3 union elements`
+ sympy/tensor/indexed.py:650:12: warning[possibly-missing-attribute] Attribute `is_Number` may be missing on object of type `Any | Basic | int | ... omitted 3 union elements`
- sympy/tensor/indexed.py:651:20: warning[possibly-missing-attribute] Attribute `is_integer` may be missing on object of type `None | Any | Basic | ... omitted 3 union elements`
+ sympy/tensor/indexed.py:651:20: warning[possibly-missing-attribute] Attribute `is_integer` may be missing on object of type `Any | Basic | int | ... omitted 3 union elements`
- sympy/tensor/indexed.py:655:16: warning[possibly-missing-attribute] Attribute `is_integer` may be missing on object of type `None | Any | Basic | ... omitted 3 union elements`
+ sympy/tensor/indexed.py:655:16: warning[possibly-missing-attribute] Attribute `is_integer` may be missing on object of type `Any | Basic | int | ... omitted 3 union elements`
- sympy/tensor/indexed.py:678:33: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Basic`, found `None | Any | Basic | ... omitted 3 union elements`
+ sympy/tensor/indexed.py:678:33: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Basic`, found `Any | Basic | int | ... omitted 3 union elements`
- Found 15892 diagnostics
+ Found 15891 diagnostics

materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/cli/mz_workload_anonymize.py:251:13: error[no-matching-overload] No overload of bound method `join` matches arguments
- Found 537 diagnostics
+ Found 536 diagnostics

rotki (https://github.com/rotki/rotki)
- rotkehlchen/tests/unit/test_makerdao.py:170:9: error[invalid-argument-type] Argument is incorrect: Expected `defaultdict[Asset, defaultdict[str, Balance]]`, found `defaultdict[Asset | Unknown, defaultdict[str, Balance] | Balance | dict[Unknown | str, Unknown | Balance] | Unknown]`
+ rotkehlchen/tests/unit/test_makerdao.py:170:9: error[invalid-argument-type] Argument is incorrect: Expected `defaultdict[Asset, defaultdict[str, Balance]]`, found `defaultdict[Asset | Unknown, defaultdict[str, Balance] | Balance | Unknown | dict[Unknown | str, Unknown | Balance]]`
- rotkehlchen/tests/unit/test_makerdao.py:171:9: error[invalid-argument-type] Argument is incorrect: Expected `defaultdict[Asset, defaultdict[str, Balance]]`, found `defaultdict[Asset | Unknown, defaultdict[str, Balance] | Balance | dict[Unknown | str, Unknown | Balance] | Unknown]`
+ rotkehlchen/tests/unit/test_makerdao.py:171:9: error[invalid-argument-type] Argument is incorrect: Expected `defaultdict[Asset, defaultdict[str, Balance]]`, found `defaultdict[Asset | Unknown, defaultdict[str, Balance] | Balance | Unknown | dict[Unknown | str, Unknown | Balance]]`

jax (https://github.com/google/jax)
- jax/_src/pallas/hlo_interpreter.py:437:37: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `int | Unknown | DynamicGridDim`
+ jax/_src/pallas/hlo_interpreter.py:437:37: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `DynamicGridDim | Unknown | int`
- jax/_src/pallas/mosaic/interpret/interpret_pallas_call.py:1895:37: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `int | Unknown | DynamicGridDim`
+ jax/_src/pallas/mosaic/interpret/interpret_pallas_call.py:1895:37: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `DynamicGridDim | Unknown | int`
- jax/_src/pallas/pallas_call.py:835:37: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `int | Unknown | DynamicGridDim`
+ jax/_src/pallas/pallas_call.py:835:37: error[invalid-argument-type] Argument is incorrect: Expected `int`, found `DynamicGridDim | Unknown | int`

scikit-learn (https://github.com/scikit-learn/scikit-learn)
- sklearn/datasets/_lfw.py:469:60: error[invalid-argument-type] Argument to class `str` is incorrect: Expected `bytes | bytearray`, found `Unknown | str`
+ sklearn/datasets/_lfw.py:469:60: error[invalid-argument-type] Argument to class `str` is incorrect: Expected `bytes | bytearray`, found `str | Unknown`

core (https://github.com/home-assistant/core)
- homeassistant/components/teslemetry/climate.py:154:37: warning[possibly-missing-attribute] Attribute `index` may be missing on object of type `Unknown | list[Unknown | str] | list[str] | None`
+ homeassistant/components/teslemetry/climate.py:154:37: warning[possibly-missing-attribute] Attribute `index` may be missing on object of type `Unknown | list[str | Unknown] | list[str] | None`

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
- tests/indexes/test_categoricalindex.py:14:9: error[type-assertion-failure] Type `CategoricalIndex[str]` does not match asserted type `CategoricalIndex[str | Unknown]`
+ tests/indexes/test_categoricalindex.py:14:9: error[type-assertion-failure] Type `CategoricalIndex[str]` does not match asserted type `CategoricalIndex[Unknown | str]`
- tests/indexes/test_categoricalindex.py:29:11: error[type-assertion-failure] Type `CategoricalIndex[str]` does not match asserted type `CategoricalIndex[str | Unknown]`
+ tests/indexes/test_categoricalindex.py:29:11: error[type-assertion-failure] Type `CategoricalIndex[str]` does not match asserted type `CategoricalIndex[Unknown | str]`
- tests/indexes/test_categoricalindex.py:31:9: error[type-assertion-failure] Type `CategoricalIndex[str]` does not match asserted type `CategoricalIndex[str | Unknown]`
+ tests/indexes/test_categoricalindex.py:31:9: error[type-assertion-failure] Type `CategoricalIndex[str]` does not match asserted type `CategoricalIndex[Unknown | str]`
+ tests/series/test_series.py:2429:9: error[type-assertion-failure] Type `Series[Timestamp]` does not match asserted type `Unknown`
- Found 4679 diagnostics
+ Found 4680 diagnostics

@carljm carljm marked this pull request as draft January 31, 2026 00:36
@carljm carljm force-pushed the claude/fix-issue-2068-x2E5Q branch from 4c9471a to dce6885 Compare January 31, 2026 00:50
@carljm carljm marked this pull request as ready for review January 31, 2026 01:02
@carljm carljm requested a review from Gankra as a code owner January 31, 2026 01:02
@carljm carljm requested a review from zanieb January 31, 2026 01:03
@sharkdp sharkdp removed their request for review February 3, 2026 13:54
@carljm carljm force-pushed the claude/fix-issue-2068-x2E5Q branch from dce6885 to 6c953b4 Compare February 11, 2026 06:59
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 11, 2026

Memory usage report

Memory usage unchanged ✅

@charliermarsh
Copy link
Member

I don't have all the context on how this works today, but did we consider something like a --system flag? The automatic merging between system and local seems somewhat questionable to me.

@carljm
Copy link
Contributor Author

carljm commented Feb 11, 2026

I don't have all the context on how this works today, but did we consider something like a --system flag? The automatic merging between system and local seems somewhat questionable to me.

I don't love the merging either, but it pre-exists this PR, and a --system flag wouldn't let us get rid of it. We added it when we added support for discovering packages installed in "the venv ty is installed in" (even when that didn't include support for system pythons), because we wanted to allow uvx --with-requirements script.py ty check script.py, and we don't want that to break just because you happen to be in a project with a .venv. You can see the full rationale for this in #21286

In practice we haven't seen any issues from the merging -- generally people are fine with ty being able to see more dependencies, we get complaints when we don't see dependencies. So erring on the side of seeing more seems like generally the right approach.

@zanieb
Copy link
Member

zanieb commented Feb 11, 2026

As you say, I think the merging in #21286 was justified by

... I don't want [uvx --with <...> ty] to break when you happen to be in a project (i.e., if we only included ty's environment when no environment is found)

However, I think it might be justifiable for ty to stop discovering system packages when you happen to be in a project? That seems more likely to be surprising and problematic than the uvx case where ty's environment is likely to be ephemeral and mostly empty?

Would you be opposed to shipping this without the merging for that case first to see if we get feedback that it's too strict?

@carljm
Copy link
Contributor Author

carljm commented Feb 12, 2026

However, I think it might be justifiable for ty to stop discovering system packages when you happen to be in a project? That seems more likely to be surprising and problematic than the uvx case where ty's environment is likely to be ephemeral and mostly empty?

Would you be opposed to shipping this without the merging for that case first to see if we get feedback that it's too strict?

Not necessarily. But can you specifically describe a scenario in which it would be "surprising and problematic" to include system packages along with project packages (keeping in mind that the system packages in this case are lower priority than the project packages) when running ty in a project, and why in that scenario it would be better not to do so? In every scenario I can think of, including them seems strictly better than not including them.

@zanieb
Copy link
Member

zanieb commented Feb 12, 2026

I think the most basic example is I'm type checking on a system which has Python packages installed for various system functionality and I get a false negative when my project imports one of those packages without declaring it as a dependency.

@carljm
Copy link
Contributor Author

carljm commented Feb 12, 2026

Yes, that makes sense. Ok, we can try this without merging.

…led into

Fixes an issue where ty couldn't resolve imports from packages installed
in a system Python environment when ty itself was installed directly in
that system Python (rather than in a virtual environment).

Previously, `SysPrefixPathOrigin::SelfEnvironment` was treated as requiring
a virtual environment (with `pyvenv.cfg`), which caused discovery to fail
for system Python installations. This change allows ty to fall back to
treating its own environment as a `SystemEnvironment` when no `pyvenv.cfg`
is found.

The priority behavior differs based on whether ty is installed in a venv:
- When ty is installed in a virtual environment (e.g., `uvx --with ...`),
  ty's venv takes priority over other discovered environments, and both
  are included in the search path
- When ty is installed in a system Python and there's a project environment
  (like `.venv`), only the project environment is used; the system Python's
  site-packages are excluded entirely

Fixes astral-sh/ty#2068

https://claude.ai/code/session_01885t5j7zeT78vRZCtu8X9C
@carljm carljm force-pushed the claude/fix-issue-2068-x2E5Q branch from 6c953b4 to 0fddbab Compare February 12, 2026 02:10
@carljm carljm requested a review from ibraheemdev as a code owner February 12, 2026 02:10
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

At some point we need to update the docs at

/// Path to your project's Python environment or interpreter.
///
/// ty uses the `site-packages` directory of your project's Python environment
/// to resolve third-party (and, in some cases, first-party) imports in your code.
///
/// If you're using a project management tool such as uv, you should not generally need to
/// specify this option, as commands such as `uv run` will set the `VIRTUAL_ENV` environment
/// variable to point to your project's virtual environment. ty can also infer the location of
/// your environment from an activated Conda environment, and will look for a `.venv` directory
/// in the project root if none of the above apply. Failing that, ty will look for a `python3`
/// or `python` binary available in `PATH`.
///
/// Passing a path to a Python executable is supported, but passing a path to a dynamic executable
/// (such as a shim) is not currently supported.
///
/// This option can be used to point to virtual or system Python environments.
to make it clear that ty will also fallback to the environment it's installed into, but that issue predates this PR so doesn't need to be done here.

We also need to amend the "ty only supports discovery of virtual environments at this time" line at

/// Path to your project's Python environment or interpreter.
///
/// ty uses the `site-packages` directory of your project's Python environment
/// to resolve third-party (and, in some cases, first-party) imports in your code.
///
/// If you're using a project management tool such as uv, you should not generally need to
/// specify this option, as commands such as `uv run` will set the `VIRTUAL_ENV` environment
/// variable to point to your project's virtual environment. ty can also infer the location of
/// your environment from an activated Conda environment, and will look for a `.venv` directory
/// in the project root if none of the above apply. Failing that, ty will look for a `python3`
/// or `python` binary available in `PATH`.
///
/// Passing a path to a Python executable is supported, but passing a path to a dynamic executable
/// (such as a shim) is not currently supported.
///
/// This option can be used to point to virtual or system Python environments.

.ok();
.ok()?;

tracing::debug!("Using site-packages from ty's environment");
Copy link
Member

Choose a reason for hiding this comment

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

sounds like we won't necessarily actually "use" the site-packages from ty's environment in the latest version of this PR?

Suggested change
tracing::debug!("Using site-packages from ty's environment");
tracing::debug!("Resolved site-packages from ty's environment");

@carljm carljm merged commit 8a04266 into main Feb 12, 2026
50 checks passed
@carljm carljm deleted the claude/fix-issue-2068-x2E5Q branch February 12, 2026 21:47
carljm added a commit that referenced this pull request Feb 14, 2026
* main: (209 commits)
  [ty] Defer base inference for functional `type(...)` classes (#22792)
  flake8-executable: allow global flags in uv shebangs (EXE003) (#22582)
  [ty] Add `replace-imports-with-any` option (#23122)
  Update html comments in mdtests (#23269)
  Apply ruff formatting to mdtests (#22935)
  [ty] Exclude test-related symbols from non-first-party packages in auto-import completions
  [ty] Refactor `CursorTest` helper to support site-packages
  [ty] Qualify inlay hint edit symbol when possibly referencing another variable (#23265)
  [ty] Avoid `UnionBuilder` overhead when creating a new union from the filtered elements of an existing union (#22352)
  [ty] Refactor TypedDict key assignment validation (#23262)
  [ty] Improve Python environment path documentation (#23256)
  [ty] loop control flow analysis using loop header definitions
  Prepare for 0.15.1 (#23253)
  Remove docker-run-action (#23254)
  [ty] Allow discovering dependencies in system Python environments (#22994)
  Ensure pending suppression diagnostics are reported (#23242)
  [`isort`] support for configurable import section heading comments (#23151)
  [ty] Fix method calls on subclasses of `Any` (#23248)
  [ty] Fix bound method access on `None` (#23246)
  Make range suppression test snapshot actually useful (#23251)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support finding dependencies in system Pythons that ty is installed into

5 participants