You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Generic function accidentally captured as closure default argument #2872
DefaultValue (the type that stores the inferred type of a parameter's default value) has a manual Visit impl that calls self.ty.recurse(f) instead of self.ty.visit(f). In the Visit framework, recurse only visits children of a node, while visit also yields the node itself when the target type matches. Every derived Visit impl uses visit, but this manual impl used recurse, so the Type stored inside a DefaultValue was invisible to any type-level traversal.
This meant that when checking whether a class attribute's type contains unbound type variables, the checker found SupportsRichComparisonT and _T (from bisect.insort's signature) inside the default value, but couldn't see the Forall/Overload wrapper that binds them — because that wrapper is the Type node that was being skipped. So the type variables looked unbound, triggering the false positive.
One-line fix: self.ty.recurse(f) → self.ty.visit(f) in DefaultValue's Visit and VisitMut impls.
Activity
tejasreddyvepala commentedon Apr 7, 2026
@grievejia Root cause identified and fix ready.
DefaultValue (the type that stores the inferred type of a parameter's default value) has a manual Visit impl that calls self.ty.recurse(f) instead of self.ty.visit(f). In the Visit framework, recurse only visits children of a node, while visit also yields the node itself when the target type matches. Every derived Visit impl uses visit, but this manual impl used recurse, so the Type stored inside a DefaultValue was invisible to any type-level traversal.
This meant that when checking whether a class attribute's type contains unbound type variables, the checker found SupportsRichComparisonT and _T (from bisect.insort's signature) inside the default value, but couldn't see the Forall/Overload wrapper that binds them — because that wrapper is the Type node that was being skipped. So the type variables looked unbound, triggering the false positive.
One-line fix: self.ty.recurse(f) → self.ty.visit(f) in DefaultValue's Visit and VisitMut impls.
Fix false positive invalid-type-var for generic functions used as clo…