Skip to content

Unify handling of self attributes in daemon#21025

Open
ilevkivskyi wants to merge 3 commits intopython:masterfrom
ilevkivskyi:clean-attr-def-daemon
Open

Unify handling of self attributes in daemon#21025
ilevkivskyi wants to merge 3 commits intopython:masterfrom
ilevkivskyi:clean-attr-def-daemon

Conversation

@ilevkivskyi
Copy link
Member

There are two situations that require special handling in the daemon:

  • When we have an attribute defined on self in a method.
  • When a variable defined in class body is inferred using an assignment in a method.

The first one is an old thing that is handled with so called "saved attributes", while the second is a recent addition handled by including relevant methods in the top-level target. Two different mechanisms with subtle differences for two similar situations make it hard to reason about what is going on in the daemon. And it will be even more complicated when we will add "staggered" interface/implementation type-checking in parallel checking, that will need to handle these situations as well.

Although this PR is strictly speaking not required for parallel checking, I propose to unify all four quadrants in the (defined variable vs inferred variable type) x (parallel checking vs daemon) square under the same mechanism: have a single flag on a function/method that specifies that this function/method may affect interface of the module, and thus should be always processed as a part of the module top-level.

This is a relatively significant change in the daemon, but IMO it is (much) cleaner, and we will probably need to rip off this band-aid sooner or later anyway. I didn't do this in my initial implementation of partial None type support, because I didn't want to touch the daemon more than strictly necessary (as I did in some of my other recent PRs), but now it seems to me that doing so creates too much tech-debt to address later.

@ilevkivskyi ilevkivskyi requested a review from JukkaL March 15, 2026 23:30
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant