Skip to content

Small type inference fix - #40

Merged
Tobias-Kohn merged 2 commits into
Tobias-Kohn:masterfrom
neilccbrown:more-type-inference-fix
Jul 25, 2026
Merged

Tobias-Kohn merged 2 commits into
Tobias-Kohn:masterfrom
neilccbrown:more-type-inference-fix

Conversation

@neilccbrown

Copy link
Copy Markdown
Contributor

It turns out the error I was having is on our side on Strype. In the course of investigating a couple more tests got added so I thought I may as well keep them. During the investigation a small bug was found with type annotations and with iterating over sets and tuples, so those fixes (plus tests) are submitted here.

with for-loop iteration and cross-function parameter inference

Covers list[Actor]/set[Actor]/tuple[Actor, ...] declared in a .pyi
stub, iterated in a for-loop, and passed into another function whose
parameter type is inferred from that call site - a combination not
exercised by the existing completer_pyi_generic_* tests, which only
check direct indexing/unpacking.
A parameter annotation (e.g. `def foo(w: Widget)`, `def foo(items:
set[Widget])`) resolved via TypeAstWalker.getType to the raw
ClassType/PrimitiveType itself. Real instance members live in
getInstanceFields, which only an Instance wrapper exposes - the raw
type's own getFields is always empty. Every other place that produces
a value of a user's type (constructor calls, function return values,
for-loop targets) already wraps it in Instance; parameter annotations
were the one gap, silently losing all completions for any annotated
parameter.

Also fills in two related gaps in annotation parsing that were
masking the fix for two of the three container kinds: `set[X]` had no
case at all (fell through to ANY_TYPE), and `tuple[X, ...]` (variadic)
was misparsed as a fixed 2-arity tuple instead of a VarTupleType -
both now mirror the handling already used for .pyi-declared types.
@Tobias-Kohn
Tobias-Kohn merged commit 85ea3e8 into Tobias-Kohn:master Jul 25, 2026
1 check passed
@neilccbrown
neilccbrown deleted the more-type-inference-fix branch July 25, 2026 07:32
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.

2 participants