-
-
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
Should stubs contain docstrings? #4881
Comments
From @Avasam
|
From @jakebailey
|
I would personally like to have docstrings in stubs. This could not only help IDEs, but also human readers. I'm quite often reading the doctrings in Typescript |
Yeah, the "maintenance nightmare" aspect of this is very real to me. I don't see us doing this unless we have something that can basically completely automatically keep the docstrings in stubs up to date (which to be clear is not infeasible). Even then I'm somewhat worried about e.g. showing docstrings that mismatch the user's package version (although we've made some recent tooling improvements in regards to managing versions). We'd probably also want to do default values, at least for simple literals. I will say as a user I'm happy with how pylance does docstrings / how responsive the hover is. So while Jake's point about the circularity of decision making is fair, I'm definitely less inclined to take on a big maintenance burden without the tooling to ensure that things stay accurate. Instead of "no docs -> some docs", it feels like we're looking at "some docs -> some docs, best case slightly faster worst case less accurate or version mismatched". Also it's not just about the burden on typeshed maintainers — I've made peace with my laziness — it's also about the burden on maintainers that ship PEP 561 stubs like numpy. |
I tend to keep default values in stubs I write, but have never considered docstrings mostly for size/complexity to maintain. Part of it is I also often copy paste method signature from library documentation which has defaults and then fill in type annotations. A smaller thing is if documentation was included I think reading stub definitions themselves would become harder. I do mostly see defaults of just float/str/None though. Complex type default (say some private callable function) I haven't encountered much and don't think would even work in a stub? edit: Maybe a simpler phrasing is manual maintenance of defaults feels feasible to me, while docstrings feels like it requires strong tooling to keep in sync. |
Defaults would be another welcome addition and indeed quite feasible, I think. |
Totally understandable; I just wanted to point out the "we have to do Y because we don't have X; we don't do X because we have Y" loop 😅 One obvious benefit of the status quo is that the docs that show up are for the Python version that the user is currently using; that's a hard thing to replicate. In TS, the Node types are versioned and people do keep them up to date, but there's a load of infrastructure on the DT side to make that work plus a pretty large group that works on them and automates getting the docs there. I will also say that Python and TS/JS have an interesting difference; in Python, docs are a part of the core language and exist at runtime, with things like |
I'm on the exact same opinion as everything hauntsaninja said here. As a python dev / consumer of Typeshed, I'd love to have docstrings where I previously didn't (because Pylance / Python Language Server only gives them for pure python source). From the maintenance PoV, it doesn't seem like a great idea to have it in the typeshed source code.
Is the main reason I alluded to the idea of relegating this to the stubs uploader (and only when the stubbed element is not present in a python source file to reference), or even to the IDEs to pull that information. (once again I haven't touched PyCharm in years so idk how it is there). For instance, here's an example of a bad-case scenario with around 2k definitions: https://github.com/Avasam/typeshed/blob/opencv2/stubs/opencv-python/cv2/cv2.pyi (originally: https://github.com/microsoft/python-type-stubs/blob/main/cv2/__init__.pyi) |
Unless we have tooling that automatically updates stub docstrings when the docstring changes in the code covered by the stub, I am against this, because of the maintenance burden. Even if we had such tooling, I actually like the terseness of the stubs -- many modules have very extensive docstrings that would completely overwhelm the current contents of the stubs, and make them less usable (to me). |
I wrote such a tool; we use it for injecting some docstrings into the pandas stubs we bundle with pylance. At this point it does not update docstrings, it just uses introspection on the module to get the docstrings and then inserts them, but it could be extended. It's the successor to https://github.com/gramster/stubsplit which was our earlier approach. |
Using that tool could we have stub packages produced by stub uploader have docstrings added instead of having docstrings in typeshed source? If we can avoid having them in typeshed source that should lower maintenance involved (still non zero to change stub uploader) while keeping IDE benefit. |
@gramster It's this project: https://github.com/gramster/docs2stubs I assume? |
Hi 👋 (reference to non-colaborators like @DetachHead not being allowed to comment here) |
You might be interested in this thread: https://mail.python.org/archives/list/[email protected]/thread/QKJWPZ6XULFWNRFZYNTXXDC26UVQPFNG/#QKJWPZ6XULFWNRFZYNTXXDC26UVQPFNG
The text was updated successfully, but these errors were encountered: