Skip to content
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

✨ Add reference (code API) docs with PEP 727, add subclass with custom docstrings for BackgroundTasks, refactor docs structure #10392

Merged
merged 50 commits into from
Oct 18, 2023

Conversation

tiangolo
Copy link
Owner

@tiangolo tiangolo commented Oct 5, 2023

✨ Add reference (code API) docs with PEP 727, add subclass with custom docstrings for BackgroundTasks, refactor docs structure.

@tiangolo tiangolo mentioned this pull request Oct 5, 2023
20 tasks
@tiangolo
Copy link
Owner Author

tiangolo commented Oct 5, 2023

📝 Docs preview for commit df4c501 at: https://5419df85.fastapitiangolo.pages.dev

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 6, 2023

If you install Black alongside mkdocstrings-python, it will use it to format long signatures (such as fastapi.FastAPI).
Also, tables are a bit too large and have an horizontal scrollbar, maybe the list or spacy formats for docstring sections would be more readable? Happy to work with you on improving rendering 🙂

@tiangolo
Copy link
Owner Author

Thanks @pawamoy!

Is there a way to render the types using the latest syntax, even if the source uses older syntax?

For example, the code for some parameters is Optional[str], to be compatible with Python 3.8, etc. But I would like that to show up in the docs as str | None.

It would probably be something like running pyupgrade on the type before it is rendered or something like that... but not sure if it's possible (or maybe there's already a config for that I haven't found).

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 12, 2023

There's no such option, but I'll see how we can make it happen. Also I suppose you cannot use from __future__ import annotations (and then use PEP 604's | syntax) for Pydantic/runtime reasons?

@tiangolo
Copy link
Owner Author

Thanks @pawamoy!

Also I suppose you cannot use from __future__ import annotations (and then use PEP 604's | syntax) for Pydantic/runtime reasons?

I'm not fully sure, I might be able to do that, at least in some places. It's funny and ironic that I would recommend people not to use from __future__ import annotations to not break/complicate their FastAPI and Pydantic apps... but I might actually be able to use it at least in some places (Pydantic already does that as well). 😅 I will try that as well.

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 12, 2023

As long as you know what you're doing 😉 And it's only for 1 year and 11 months, until 3.9 is EOL 🤫

Comment on lines 644 to 646
"""
---
"""
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pawamoy I'm noticing that to render the __init__() parameters I need to have some non-empty docstring in the __init__() method, even if there's already a class docstring...

Am I doing something wrong in the configs or is it expected?

Copy link
Sponsor Contributor

@pawamoy pawamoy Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that in the PR yes. That's probably an oversight (in the PEP 727 extension), I'll take a look :)

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now fixed by latest versions of Griffe and griffe-typingdoc 😄

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! ...although I can't seem to make it work yet 🤔

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tell me what is not working? I tried locally to remove the docstring from fastapi.FastAPI.__init__ and the parameters are correctly inserted into the class docs.

@tiangolo
Copy link
Owner Author

Awesome, thanks @pawamoy! 🚀

For some reason, I hadn't found the insiders installation, and now I see that it's quite open there... I was probably too tired and didn't see it 😅 🙈

@tiangolo
Copy link
Owner Author

📝 Docs preview for commit e2c3672 at: https://690c34e1.fastapitiangolo.pages.dev

@tiangolo
Copy link
Owner Author

📝 Docs preview for commit c34b8c9 at: https://eca9a21b.fastapitiangolo.pages.dev

@tiangolo tiangolo changed the title ✨ Add reference (code API) docs ✨ Add reference (code API) docs, add subclass with custom docstrings for BackgroundTasks, refactor docs structure Oct 18, 2023
@tiangolo
Copy link
Owner Author

📝 Docs preview for commit 77cb0c7 at: https://ecb1abc9.fastapitiangolo.pages.dev

@tiangolo tiangolo changed the title ✨ Add reference (code API) docs, add subclass with custom docstrings for BackgroundTasks, refactor docs structure ✨ Add reference (code API) docs with PEP 727, add subclass with custom docstrings for BackgroundTasks, refactor docs structure Oct 18, 2023
@tiangolo
Copy link
Owner Author

📝 Docs preview for commit ac82b9e at: https://2124dde5.fastapitiangolo.pages.dev

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 18, 2023

I'll tell you when griffe-typing-deprecated is up-to-date with latest Griffe so you can list it in mkdocs.yml 🙂

@tiangolo
Copy link
Owner Author

Thanks @pawamoy! For now, I'll merge and release this. 😎 🚀

@tiangolo tiangolo merged commit 05ca41c into master Oct 18, 2023
35 checks passed
@tiangolo tiangolo deleted the ref-docs branch October 18, 2023 12:36
@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 18, 2023

Congrats! I'm amazed by your efficiency here: in just a few days you managed to document the (almost?) entire API 🤯 Also it's super exciting to see a decently-sized code base use PEP 727 docs 😄 It's looking great!

@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Oct 18, 2023

Oh and for signature_crossrefs to take effect, you need to enable show_signature_annotations too!

nilslindemann added a commit to nilslindemann/fastapi that referenced this pull request Oct 18, 2023
nilslindemann added a commit to nilslindemann/fastapi that referenced this pull request Oct 18, 2023
nilslindemann added a commit to nilslindemann/fastapi that referenced this pull request Oct 18, 2023
nilslindemann added a commit to nilslindemann/fastapi that referenced this pull request Oct 18, 2023
nilslindemann added a commit to nilslindemann/fastapi that referenced this pull request Jan 17, 2024
These were added to the Englisch docs in tiangolo#10392.

I went through all instances of:

* docs/index.md
* docs/features.md
* docs/fastapi-people.md

in the rest of the docs and added this where missing. The PRs for the German translations (tiangolo#10283, tiangolo#10284, tiangolo#10285) already contain this change.
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.

None yet

2 participants