{{ message }}
Repository navigation
Fix false positives on property setters during variance inference - #11840
Open
crypt0lith wants to merge 1 commit into
Open
crypt0lith wants to merge 1 commit into
crypt0lith wants to merge 1 commit into
Conversation
When a decorator's type is incomplete, getTypeOfFunction caches the decorated type as final, and member access on a function drops the base type's incompleteness before reporting a missing attribute. Cache the decorated type as incomplete when any decorator is, and keep the base type's incompleteness in the function member lookup. Fixes microsoft#11835
Contributor
crypt0lith
had a problem deploying
to
github-pages
October 6, 2026 17:22 — with
GitHub Actions
Failure
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #11835
Since #9102 (1.1.383), specializing a generic type alias infers its variance. When a property getter's return annotation specializes an alias that refers back to a class with inferred variance, pyright reports the setter's decorator as an unknown attribute of a function and the getter as obscured.
Root cause
Inferring the class's variance evaluates the declared type of each member. For a property, that is the setter, whose decorator refers to the getter while the getter is still being decorated, so the decorator's base type is an incomplete function.
getTypeOfMemberAccessWithBaseTypelooks up an attribute of a function on thefunctionorMethodTypeclass, but passes that lookup a base type withoutisIncomplete, so it reports the missing attribute.getTypeOfFunctioncaches the decorated type as final even when a decorator's type was incomplete. The setter's decorated type staysAnyafter the getter is complete, and the redeclaration check reports the getter as obscured.Fix
The function member lookup keeps the base type's incompleteness, and a decorated type built from an incomplete decorator is cached as incomplete, so it is evaluated again once the getter is complete.
Test
diagnostics.propertySetterVarianceInference.fourslash.ts, a fourslash test because the sample-file harness evaluates the getter before the checker reaches the annotation:test1.py: a getter and setter whose return annotation specializes an alias referring to the class. Must stay clean.test2.py: the same with a misspelled setter attribute. Must still flag it as an unknown attribute ofproperty, and the getter as obscured.