[ty] supress some trivial expr inlay hints#21367
Conversation
| x = 1 | ||
| y[: Literal[1]] = x |
There was a problem hiding this comment.
This case is why this approach is mediocre. The type-directed approach would catch this trivially.
There was a problem hiding this comment.
I don't think this is actually so bad? It tells the user that we inferred the type of y as Literal[1], but mypy would infer it as int here -- that's potentially useful information. The y = x assignment could also happen much lower down in the function, far away from the initial x = 1 assignment
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
| x = 1 | ||
| y[: Literal[1]] = x |
There was a problem hiding this comment.
I don't think this is actually so bad? It tells the user that we inferred the type of y as Literal[1], but mypy would infer it as int here -- that's potentially useful information. The y = x assignment could also happen much lower down in the function, far away from the initial x = 1 assignment
| return x | ||
|
|
||
| x1, y1 = (1, 'abc') | ||
| x2[: Literal[1]], y2[: Literal["abc"]] = (x1, y1) |
There was a problem hiding this comment.
this, on the other hand, feels kinda yucky to me 😆
It's everyone's favourite language corner case! Also having kicked the tires on it, I'm pretty happy to call this (in conjunction with #21367): Fixes astral-sh/ty#494 There's cases where you can make noisy Literal hints appear, so we can always iterate on it, but this handles like, 98% of the cases in the wild, which is great. --------- Co-authored-by: David Peter <[email protected]>
* origin/main: (38 commits) [ty] Make implicit submodule imports only occur in global scope (#21370) [ty] introduce local variables for `from` imports of submodules in `__init__.py(i)` (#21173) [`ruff`] Ignore `str()` when not used for simple conversion (`RUF065`) (#21330) [ty] implement `typing.NewType` by adding `Type::NewTypeInstance` [ty] supress inlay hints for `+1` and `-1` (#21368) [ty] Use type context for inference of generic constructors (#20933) [ty] Improve generic call expression inference (#21210) [ty] supress some trivial expr inlay hints (#21367) [`configuration`] Fix unclear error messages for line-length values exceeding `u16::MAX` (#21329) [ty] Fix incorrect inference of `enum.auto()` for enums with non-`int` mixins, and imprecise inference of `enum.auto()` for single-member enums (#20541) [`refurb`] Detect empty f-strings (`FURB105`) (#21348) [ty] provide `import` completion when in `from <name> <name>` statement (#21291) [ty] elide redundant inlay hints for function args (#21365) Fix syntax error false positive on alternative `match` patterns (#21362) Add a new "Opening a PR" section to the contribution guide (#21298) [`flake8-simplify`] Fix SIM222 false positive for `tuple(generator) or None` (`SIM222`) (#21187) Rebuild ruff binary instead of sharing it across jobs (#21361) [ty] Fix `--exclude` and `src.exclude` merging (#21341) [ty] Add support for properties that return `Self` (#21335) Add upstream linter URL to `ruff linter --output-format=json` (#21316) ...
I'm not 100% sold on this implementation, but it's a strict improvement and it adds a ton of snapshot tests for future iteration.
Part of astral-sh/ty#494