Skip to content

Conversation

@ibraheemdev
Copy link
Member

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from 09d2478 to 2e13754 Compare November 3, 2025 00:44
@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

mypy_primer results

Changes were detected when running on open source projects
dulwich (https://github.com/dulwich/dulwich)
- dulwich/pack.py:1702:83: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 175 diagnostics
+ Found 174 diagnostics

pydantic (https://github.com/pydantic/pydantic)
- pydantic/_internal/_validators.py:161:16: error[invalid-return-type] Return type does not match returned value: expected `Pattern[bytes]`, found `Pattern[str | bytes]`
+ pydantic/_internal/_validators.py:161:16: error[invalid-return-type] Return type does not match returned value: expected `Pattern[bytes]`, found `Pattern[bytes | str]`

pandera (https://github.com/pandera-dev/pandera)
+ tests/mypy/pandas_modules/pandas_dataframe.py:35:12: error[no-matching-overload] No overload of bound method `pipe` matches arguments
- tests/mypy/pandas_modules/pandas_dataframe.py:41:12: error[invalid-return-type] Return type does not match returned value: expected `DataFrame[SchemaOut]`, found `DataFrame[Schema] | DataFrame[SchemaOut]`
+ tests/mypy/pandas_modules/pandas_dataframe.py:41:12: error[invalid-return-type] Return type does not match returned value: expected `DataFrame[SchemaOut]`, found `DataFrame[SchemaOut] | DataFrame[Schema]`
- Found 1637 diagnostics
+ Found 1638 diagnostics

Expression (https://github.com/cognitedata/Expression)
- tests/test_result.py:491:21: error[invalid-argument-type] Argument to bound method `or_else` is incorrect: Expected `Result[Literal[42], Any]`, found `Result[Literal[0], Any]`
- tests/test_result.py:509:21: error[invalid-argument-type] Argument to bound method `or_else` is incorrect: Expected `Result[Any, Literal["original error"]]`, found `Result[Any, Literal["new error"]]`
- Found 200 diagnostics
+ Found 198 diagnostics

sphinx (https://github.com/sphinx-doc/sphinx)
- sphinx/domains/python/__init__.py:672:42: error[index-out-of-bounds] Index 0 is out of bounds for string `Literal[""]` with length 0
- Found 515 diagnostics
+ Found 514 diagnostics

vision (https://github.com/pytorch/vision)
- torchvision/prototype/transforms/_misc.py:34:13: error[invalid-assignment] Object of type `dict[Any, Sequence[int] & ~Top[dict[Unknown, Unknown]]]` is not assignable to `Sequence[int] | dict[type, Sequence[int] | None]`
- Found 1503 diagnostics
+ Found 1502 diagnostics

cloud-init (https://github.com/canonical/cloud-init)
- tests/unittests/sources/test_lxd.py:40:5: error[non-subscriptable] Cannot subscript object of type `int` with no `__getitem__` method
- tests/unittests/test_net.py:5337:41: warning[possibly-missing-attribute] Attribute `keys` may be missing on object of type `Unknown | list[Unknown | str] | dict[Unknown | str, Unknown | str | None] | dict[Unknown, Unknown]`
- tests/unittests/test_net.py:5494:41: warning[possibly-missing-attribute] Attribute `keys` may be missing on object of type `Unknown | list[Unknown | str] | dict[Unknown | str, Unknown | str | None] | dict[Unknown | str, Unknown | str]`
- Found 1134 diagnostics
+ Found 1131 diagnostics

meson (https://github.com/mesonbuild/meson)
+ mesonbuild/build.py:1293:9: error[invalid-assignment] Object of type `list[Sequence[str | Literal[False]] | Literal[False]]` is not assignable to attribute `install_dir` of type `list[str | Literal[False]]`
- Found 1664 diagnostics
+ Found 1665 diagnostics

scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/format.py:74:16: error[invalid-return-type] Return type does not match returned value: expected `PyprojectFormatter | dict[str, str]`, found `dict[str, Literal["*"]]`
- Found 49 diagnostics
+ Found 48 diagnostics

colour (https://github.com/colour-science/colour)
- colour/recovery/otsu2018.py:1606:21: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None]) | (bound method dict[Unknown, Unknown].__setitem__(key: Unknown, value: Unknown, /) -> None)` cannot be called with a key of type `Node_Otsu2018` and a value of type `Unknown | list[Unknown] | dict[Unknown, Unknown] | int` on object of type `Unknown | list[Unknown] | dict[Unknown, Unknown] | int`
- colour/recovery/otsu2018.py:1607:21: error[unsupported-operator] Operator `+=` is unsupported between objects of type `list[Unknown]` and `Literal[1]`
- colour/recovery/otsu2018.py:1607:21: error[unsupported-operator] Operator `+=` is unsupported between objects of type `dict[Unknown, Unknown]` and `Literal[1]`
- colour/recovery/otsu2018.py:1610:17: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None]) | (bound method dict[Unknown, Unknown].__setitem__(key: Unknown, value: Unknown, /) -> None)` cannot be called with a key of type `Node_Otsu2018` and a value of type `int` on object of type `Unknown | list[Unknown] | dict[Unknown, Unknown] | int`
- colour/recovery/otsu2018.py:1610:54: error[invalid-argument-type] Argument to function `len` is incorrect: Expected `Sized`, found `Unknown | list[Unknown] | dict[Unknown, Unknown] | int`
- colour/recovery/otsu2018.py:1611:17: warning[possibly-missing-attribute] Attribute `append` may be missing on object of type `Unknown | list[Unknown] | dict[Unknown, Unknown] | int`
- Found 567 diagnostics
+ Found 561 diagnostics

static-frame (https://github.com/static-frame/static-frame)
+ static_frame/test/unit/test_series.py:4489:37: error[no-matching-overload] No overload of function `round` matches arguments
- Found 2004 diagnostics
+ Found 2005 diagnostics

core (https://github.com/home-assistant/core)
+ homeassistant/components/homekit/config_flow.py:502:9: error[invalid-assignment] Object of type `Any` is not assignable to `EntityFilterDict`
+ homeassistant/components/homekit/config_flow.py:546:9: error[invalid-assignment] Object of type `Any` is not assignable to `EntityFilterDict`
+ homeassistant/components/homekit/config_flow.py:649:9: error[invalid-assignment] Object of type `Any` is not assignable to `EntityFilterDict`
- Found 14455 diagnostics
+ Found 14458 diagnostics

No memory usage changes detected ✅

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-assignment 4 3 0
invalid-argument-type 0 3 0
invalid-return-type 0 1 2
possibly-missing-attribute 0 3 0
no-matching-overload 2 0 0
unsupported-operator 0 2 0
index-out-of-bounds 0 1 0
non-subscriptable 0 1 0
unused-ignore-comment 0 1 0
Total 6 15 2

Full report with detailed diff (timing results)

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 3, 2025

CodSpeed Performance Report

Merging #21210 will degrade performances by 7.82%

Comparing ibraheem/generic-call-inference (4aa5f3a) with main (d258302)

Summary

❌ 4 regressions
✅ 18 untouched
⏩ 30 skipped1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Mode Benchmark BASE HEAD Change
Simulation hydra-zen 861.8 ms 927.5 ms -7.08%
WallTime medium[colour-science] 15.1 s 16.3 s -7.82%
WallTime medium[pandas] 43.1 s 45.4 s -5.08%
WallTime medium[static-frame] 13 s 13.6 s -4.63%

Footnotes

  1. 30 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch 2 times, most recently from 9ad8d67 to 67143b9 Compare November 3, 2025 18:16
@ibraheemdev ibraheemdev changed the base branch from main to ibraheem/typed-dict-assignability November 3, 2025 18:18
@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from 67143b9 to 24e37e9 Compare November 3, 2025 18:18
@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from 24e37e9 to 54dec10 Compare November 3, 2025 20:35
@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from 54dec10 to e967176 Compare November 3, 2025 21:08
Base automatically changed from ibraheem/typed-dict-assignability to main November 3, 2025 21:57
@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from e967176 to 0dc3902 Compare November 4, 2025 16:55
@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from 0dc3902 to a0144fd Compare November 4, 2025 17:37
@ibraheemdev ibraheemdev marked this pull request as ready for review November 4, 2025 20:25
@ibraheemdev ibraheemdev requested a review from carljm as a code owner November 4, 2025 20:25
@ibraheemdev
Copy link
Member Author

ibraheemdev commented Nov 4, 2025

I imagine we could avoid the performance regression by special casing x: ... | None = f() to avoid the inference attempt using only None as the type context, but I'm a little hesitant to make that change, as there are (rare) cases where we might want to narrow to None. Most of the regressions seem relatively reasonable, other than colour.

Also note that a lot of the diagnostic improvements won't be seen in this PR directly, but #20933 (which is currently stacked on top of this PR).

ibraheemdev added a commit that referenced this pull request Nov 5, 2025
…nce (#21275)

## Summary

Splitting this one out from #21210. This is also something that should be made obselete by the new constraint solver, but is easy enough to fix now.
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Do we understand what's causing the performance regression? Is it that we need to clone bindings or is it something else?

@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from 0f6ddfb to 2b79ab0 Compare November 6, 2025 14:47
@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from 2b79ab0 to 0629a65 Compare November 6, 2025 15:22
@ibraheemdev
Copy link
Member Author

Most of the performance regressions have been resolved. There is an unavoidable regression when assigning the result of a generic call to a union, as we have to attempt inference multiple times for each element of the union.

@carljm
Copy link
Contributor

carljm commented Nov 6, 2025

Can you take a look at the new diagnostics in the ecosystem report? Just taking a quick glance, I see in HomeAssistant a few occurrences of "object of type Any is not assignable ..." which definitely doesn't look right.

@ibraheemdev
Copy link
Member Author

ibraheemdev commented Nov 6, 2025

It looks like those failures are due to TypedDict being assignable to None, which confuses overload evaluation. The weird diagnostic should be fixed by #21267, the actual type we infer (with type context) is Any | None there, not Any.

I added a failing test to track those.

@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch 2 times, most recently from a786a14 to 46b938b Compare November 7, 2025 15:38
@ibraheemdev ibraheemdev force-pushed the ibraheem/generic-call-inference branch from 46b938b to 966b438 Compare November 7, 2025 16:56
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.

I'm not too familiar with this machinery, but from what I can tell this all looks reasonable to me, and I definitely approve of all of the semantics changes I see in the tests! This is, as ever, very cool work

@ibraheemdev ibraheemdev enabled auto-merge (squash) November 10, 2025 21:27
@ibraheemdev ibraheemdev merged commit 98869f0 into main Nov 10, 2025
40 checks passed
@ibraheemdev ibraheemdev deleted the ibraheem/generic-call-inference branch November 10, 2025 21:29
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

Oops, I had a couple draft comments from a review I started on Friday but hadn't completed yet. Nothing important, just things to consider for future.

python-version = "3.12"
```

`generic_list.py`:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: should these just be another heading layer? Our usual approach is to reserve filenames for tests that actually need to be multi-file (because they are testing cross-module behavior / imports) and use headings when we are just trying to group related tests together.

return [x]

a = f(1)
reveal_type(a) # revealed: list[Literal[1]]
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably do literal promotion here?

Copy link
Member

Choose a reason for hiding this comment

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

that might be fixed in #21320 :-)

ibraheemdev added a commit that referenced this pull request Nov 10, 2025
dcreager added a commit that referenced this pull request Nov 11, 2025
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants