Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Ignore generic specialization in layout compatibility checks#25178

Merged
charliermarsh merged 2 commits into
mainfrom
charlie/layout
May 18, 2026
Merged

[ty] Ignore generic specialization in layout compatibility checks#25178
charliermarsh merged 2 commits into
mainfrom
charlie/layout

Conversation

@charliermarsh

@charliermarsh charliermarsh commented May 15, 2026

Copy link
Copy Markdown
Member

Summary

Every time someone tries to touch this code, it gets rejected, so I don't have high hopes here. Anyway...

Previously, a generic disjoint base and a subclass of that base could be marked as incompatible if the type arguments didn't line up. But at runtime, CPython's instance layout check isn't affected by type arguments. A concrete example is:

import asyncio

class Future(asyncio.Future): ...
class Task(asyncio.Task): ...
class SubClass(Task, Future): ...

asyncio.Task is a subclass of asyncio.Future, so these bases can coexist in the same MRO. But before, we ended up doing a comparison like Task[Unknown] <: Future[Unknown], which I believe ends up failing because Unknown <: Unknown is false under subtyping?

Closes astral-sh/ty#3466.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 15, 2026
@astral-sh-bot

astral-sh-bot Bot commented May 15, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134.

@astral-sh-bot

astral-sh-bot Bot commented May 15, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented May 15, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-argument-type 2 0 0
instance-layout-conflict 0 1 0
unresolved-attribute 0 0 1
Total 2 1 1

Raw diff:

beartype (https://github.com/beartype/beartype)
- beartype/claw/_ast/_kind/clawastimport.py:698:40 error[unresolved-attribute] Attribute `get` is not defined on `None` in union `None | (Iota & BeartypeDecorPlaceTrieABC) | (Unknown & BeartypeDecorPlaceTrieABC)`
+ beartype/claw/_ast/_kind/clawastimport.py:698:40 error[unresolved-attribute] Attribute `get` is not defined on `None` in union `None | (dict[str, dict[str, Divergent] | None] & BeartypeDecorPlaceTrieABC) | (Iota & BeartypeDecorPlaceTrieABC) | (Unknown & BeartypeDecorPlaceTrieABC)`

core (https://github.com/home-assistant/core)
+ homeassistant/core.py:633:43 error[invalid-argument-type] Argument to bound method `HomeAssistant.async_create_task` is incorrect: Expected `Coroutine[Any, Any, _R@async_add_job]`, found `(((...) -> Coroutine[Any, Any, _R@async_add_job] | _R@async_add_job) & Coroutine[object, Never, object]) | Coroutine[Any, Any, _R@async_add_job]`
+ homeassistant/core.py:960:43 error[invalid-argument-type] Argument to bound method `HomeAssistant.async_create_task` is incorrect: Expected `Coroutine[Any, Any, _R@async_run_job]`, found `(((...) -> Coroutine[Any, Any, _R@async_run_job] | _R@async_run_job) & Coroutine[object, Never, object]) | Coroutine[Any, Any, _R@async_run_job]`

pyodide (https://github.com/pyodide/pyodide)
- src/py/pyodide/webloop.py:169:7 error[instance-layout-conflict] Class will raise `TypeError` at runtime due to incompatible bases: Bases `Task` and `PyodideFuture` cannot be combined in multiple inheritance

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review May 15, 2026 12:40
@charliermarsh charliermarsh changed the title [ty] View ecosystem results for layout [ty] Ignore generic specialization in layout compatibility checks May 15, 2026
Comment thread crates/ty_python_semantic/src/types/diagnostic.rs
@charliermarsh charliermarsh enabled auto-merge (squash) May 18, 2026 21:44
@charliermarsh charliermarsh merged commit 2c32fed into main May 18, 2026
58 checks passed
@charliermarsh charliermarsh deleted the charlie/layout branch May 18, 2026 21:48
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
…tral-sh#25178)

## Summary

Every time someone tries to touch this code, it gets rejected, so I
don't have high hopes here. Anyway...

Previously, a generic disjoint base and a subclass of that base could be
marked as incompatible if the type arguments didn't line up. But at
runtime, CPython's instance layout check isn't affected by type
arguments. A concrete example is:

```python
import asyncio

class Future(asyncio.Future): ...
class Task(asyncio.Task): ...
class SubClass(Task, Future): ...
```

`asyncio.Task` is a subclass of `asyncio.Future`, so these bases can
coexist in the same MRO. But before, we ended up doing a comparison like
`Task[Unknown] <: Future[Unknown]`, which I believe ends up failing
because `Unknown <: Unknown` is false under subtyping?
anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request May 28, 2026
…tral-sh#25178)

## Summary

Every time someone tries to touch this code, it gets rejected, so I
don't have high hopes here. Anyway...

Previously, a generic disjoint base and a subclass of that base could be
marked as incompatible if the type arguments didn't line up. But at
runtime, CPython's instance layout check isn't affected by type
arguments. A concrete example is:

```python
import asyncio

class Future(asyncio.Future): ...
class Task(asyncio.Task): ...
class SubClass(Task, Future): ...
```

`asyncio.Task` is a subclass of `asyncio.Future`, so these bases can
coexist in the same MRO. But before, we ended up doing a comparison like
`Task[Unknown] <: Future[Unknown]`, which I believe ends up failing
because `Unknown <: Unknown` is false under subtyping?
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.

Instance layout conflict false positive with multiple inheritance from C implementations of asyncio.Task and asyncio.Future

2 participants