[ty] Allow constrained TypeVars with compatible constraints to satisfy each other
When a constrained TypeVar is passed to a function expecting another constrained
TypeVar, check whether each constraint of the actual TypeVar is assignable to at
least one constraint of the formal TypeVar. This fixes false-positive errors when
wrapping functions from external packages that define private TypeVars with the
same (or compatible) constraint sets.
Fixes https://github.com/astral-sh/ty/issues/2728
https://claude.ai/code/session_01FbdSnWQPg9EZgcwbR5Kujp
[ty] Fix comparison operators with literal type annotations in dunder methods
When a class defines a comparison method like `__gt__(self, other: Literal[0])`,
using the comparison operator `m > 0` would fail with "Unsupported `>` operation"
even though the direct method call `m.__gt__(0)` worked correctly.
The issue was in `infer_binary_type_comparison`: when comparing a `NominalInstance`
with a literal type (`IntLiteral`, `StringLiteral`, or `BytesLiteral`), the code
unconditionally widened the literal to its base type (`int`, `str`, `bytes`) before
attempting dunder method lookup. This meant that a method expecting `Literal[0]`
would receive `int` instead, causing the type check to fail.
The fix modifies the literal + NominalInstance cases to first try the dunder call
with the original literal type, then fall back to widening only if that fails.
This allows methods annotated with literal types to work correctly while
maintaining backward compatibility with methods expecting the base types.
Also removes unnecessary catch-all patterns for StringLiteral, BytesLiteral, and
LiteralString that were not exercised by any tests.
https://claude.ai/code/session_01YMYPi46ZrejvcYnNoqB759
[ty] Clarify that `./src` must not be a package for auto-detection
Update the `environment.root` auto-detection to handle `./src`,
`./<project-name>`, and `./python` directories uniformly: all three
are now additive (any combination can be included), rather than
`./src` and `./<project-name>` being mutually exclusive alternatives.
The project root (`.`) is always included. Additionally, each of the
following directories is included if it exists and is not a package
(i.e., does not contain `__init__.py` or `__init__.pyi`):
- `./src`
- `./<project-name>` (when `./<project-name>/<project-name>` exists)
- `./python`
This simplifies both the implementation and the documentation.
Closes astral-sh/ty#2722
https://claude.ai/code/session_01UrvvEWGPheFEYc1rFbzxA5