-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[red-knot] annotated assignments without RHS in stubs should still be bindings #16264
Comments
We probably also want to do this generally in stubs, including in class body scopes, because people often omit right-hand-sides from annotated assignments in stubs, so we can't assume that Perhaps in an ideal world, the recommended approach in stubs would be to include class-level defaults (or at least This cropped up as causing a false positive in tomllib, see #16036 (comment) |
btw. in one of the early versions of #16036 I actually had logic that special cased stubs & ABC's, but @sharkdp asked to remove it here #16036 (comment) - I have the code stashed, including the ABC wiring - so again, just saying, I'd be happy to re-wire the boundness/declaredness. |
I think @sharkdp was right that we should handle By "a deeper layer" I mean that already when we create the initial Definitions in building the semantic index, we should always consider an annotated assignment in a stub with no RHS to be both a binding and a declaration, rather than just a declaration. And then in type inference we should record it as both a binding and a declaration of the annotated type. This reflects the fact that in general, in a stub file, I think implementing this generalized approach will also help with resolution of the symbol boundness-vs-declaredness issue. There's a TODO comment in |
Oh, I'd love to implement this way. I haven't touched semantic index so far, so will be a great opportunity to take my relationship with it to the next level!
Yeah, I've seen that from the very beginning ;-) |
Description
Otherwise, we get into trouble when a special form (say
Protocol
) is used within the global scope of the same stub file where it is defined, because that's just a local use, which only respects bindings.This doesn't affect special forms that are used in annotation position (e.g.
ClassVar
) because all annotation expressions are lazy in stub files, meaning they use the public type.The text was updated successfully, but these errors were encountered: