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

Proc macro documentation #1585

Merged
merged 6 commits into from
May 3, 2021
Merged

Proc macro documentation #1585

merged 6 commits into from
May 3, 2021

Conversation

mejrs
Copy link
Member

@mejrs mejrs commented Apr 29, 2021

Adds documentation for the proc macros.

It's mostly meant as a quick reference, as well as a future place to add doc aliases (they are not very discoverable right now).

Rendered

image

image

image

image

image

image

Copy link
Member

@kngwyu kngwyu left a comment

Choose a reason for hiding this comment

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

Wow, this is amazing. I hope this would improve experiences for new contributors.

@mejrs
Copy link
Member Author

mejrs commented Apr 30, 2021

I figured out that docs for #pyclass and #pymethods don't get rendered if the multiple_pymethods flag is on, this should fix that

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

👍 it's so nice to have this documentation! Thank you for taking the time to write it 💯

I have just a few questions, suggestions and tweaks...

/// | `weakref` | Allows this class to be [weakly referenceable][6]. |
/// | `extends = BaseType` | Use a custom baseclass. Defaults to [`PyAny`][4] |
/// | `subclass` | Allows Python classes to inherit from this class. |
/// | `unsendable`<!-- hack to stop the column from wrapping -->&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; | Required if your struct is not [`Send`][3]. Rather than using `unsendable`, consider implementing your struct in a threadsafe way by e.g. substituting [`Rc`][8] with [`Arc`][9]. By using `unsendable`, your class will panic when accessed by another thread.|
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain how this hack works? 🧠

Copy link
Member Author

Choose a reason for hiding this comment

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

They're whitespaces that do not permit wrapping.

If something tries minimizing the table column, "ham spam eggs" can wrap around their spaces, but "ham spam eggs" (ham&#160;spam&#160;eggs) will not.

Copy link
Member

@davidhewitt davidhewitt May 3, 2021

Choose a reason for hiding this comment

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

Ah, understood.

I think it's slightly more intuitive (although admittedly more ugly) to do something like

<span style="white-space: pre">`name = "python_name"`</span>

on the rows that we don't want to wrap, but I'll do that in a separate PR.

pyo3-macros/src/lib.rs Outdated Show resolved Hide resolved
pyo3-macros/src/lib.rs Outdated Show resolved Hide resolved
pyo3-macros/src/lib.rs Show resolved Hide resolved
pyo3-macros/src/lib.rs Show resolved Hide resolved
@davidhewitt
Copy link
Member

👍 thanks again for this, it's brilliant.

@davidhewitt davidhewitt merged commit 81ad5b3 into PyO3:main May 3, 2021
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.

3 participants