-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Rework the "Incomplete stubs" section #9548
Conversation
Also move it to the "Conventions" section due its scope change. Closes: python#8955
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel sort-of neutral on this.
Most of our stubs these days are contributed using the create_baseline_stubs
script. For stubs created using that script, there's indeed no reason to produce partial or incomplete stubs. The idea is to produce "low-quality but complete" stubs, and iterate on them in further PRs to slowly improve the quality.
But not all stubs contributions follow this process: our recently-contributed TensorFlow stubs, for example, are quite incomplete, but what has been contributed has been of a much higher quality than the stubs that create_baseline_stubs
would autogenerate. The idea here is different: to produce "high-quality but incomplete" stubs, and iterate on them in further PRs to slowly work towards completion.
Is there a strong reason to forbid the second way of doing things?
In theory, anything missing can be filled in by stubgen. I've never tried it, but maybe pytype's Idk if having to provide "stubtest complete" stubs could discourage a potential new contributor to add a new stub gets the feeling this will mean having to put in more work that what they thought they needed. Or if it increases the complexity of their initial stub due to stubtest quirks. |
I was assuming some libraries would be treated as exceptional cases. In tensorflow’s case using mypy’s stubgen on it last I tried it crashed. Also problematically tensorflow’s relies on heavy dynamic import patching so most classes/functions where they are defined is in an internal implementation detail and the public documented location is not what stubgen can generate. The last problem is tensorflow also uses a good amount of dynamic patching including for some core methods so my previous experience using pyright generated stubs, they were prone to false positives that my team had bad experience with them. But at same time I think tensorflow is pretty weird case and most libraries generated stubs shouldn’t hit these issues. I wouldn’t design rules based on tensorflow and as long as special cases can still be allowed as needed this recommendation seems fine. |
To be clear: I don't think anybody is proposing to lay down rules that can never be broken, so we almost certainly would still have accepted the TensorFlow stubs PR even if this PR had already been merged. But that's very useful feedback about why you went about TensorFlow stubs the way you did, and makes me lean in favour of this PR being merged :) |
Maybe it would be useful to just explain Incomplete annotationsWhen submitting new stubs, it is not necessary to annotate all arguments, return types, and fields. Such items should either be left unannotated or use from _typeshed import Incomplete
field: Incomplete # unannotated
def foo(x): ... # unannotated argument and return type
def foo(x: Incomplete | None = None) -> list[Incomplete]: ...
|
So, any input by one of the co-maintainers? @JelleZijlstra @AlexWaygood @hauntsaninja @Akuli I personally like the short version in my last comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with either. @hmc-cs-mdrissi's comments about why he's doing TensorFlow stubs the way he is have resolved my prior concerns about the current wording. Your alternative also looks fine :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to see our conventions being documented :) A couple nits.
Co-authored-by: Akuli <[email protected]>
I have now substituted and concise version. |
Also move it to the "Conventions" section due its scope change.
Closes: #8955