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

Expand on AsPyPointer docs and un-ignore doc examples #2350

Merged
merged 4 commits into from May 6, 2022

Conversation

mejrs
Copy link
Member

@mejrs mejrs commented May 2, 2022

@mejrs mejrs added the CI-no-fail-fast If one job fails, allow the rest to keep testing label May 3, 2022
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.

👍 a lot of great tidy-ups here, thank you! Few quick thoughts about the guide changes...

guide/src/building_and_distribution.md Show resolved Hide resolved
Comment on lines 607 to 626
Note that unlike class variables defined in Python code, class attributes defined in Rust cannot
be mutated at all:
```rust,ignore
// Would raise a `TypeError: can't set attributes of built-in/extension type 'MyClass'`
pyo3::py_run!(py, my_class, "my_class.my_attribute = 'foo'")
```rust,should_panic
# use pyo3::prelude::*;
# #[pyclass]
# struct MyClass {}
# #[pymethods]
# impl MyClass {
# #[classattr]
# fn my_attribute() -> String {
# "hello".to_string()
# }
# }
#
Python::with_gil(|py| {
let my_class = py.get_type::<MyClass>();

// Would raise a `TypeError: can't set attributes of built-in/extension type 'MyClass'`
pyo3::py_run!(py, my_class, "my_class.my_attribute = 'foo'")
});
Copy link
Member

Choose a reason for hiding this comment

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

As per #2349 shall we just change the documentation here? I'm not sure if it's worth us investing lots of effort to change this, or how hard it would be.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've deleted it for now.

@@ -311,7 +311,7 @@ from anywhere as long as your `app.py` is in the expected directory (in this exa
that directory is `/usr/share/python_app`).

`src/main.rs`:
```ignore
```no_run
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
```no_run
```rust,no_run

... maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I decided against running it because it loads things in a very platform dependent way.

Copy link
Member

Choose a reason for hiding this comment

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

I was just wondering whether the rust tag was also needed to give nice syntax highlighting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right. For some reason I glanced over that it would still be no_run

@@ -722,7 +722,7 @@ If `T` implements `Clone`, you can extract `T` itself.
In addition, you can also extract `&PyCell<T>`, though you rarely need it.

Before:
```ignore
```compile_fail
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure it's worth changing bits like this which we know have old syntax, it's presumably just wasting CPU cycles to assert that the compile fails. Is there a particular intended benefit to this change?

Copy link
Member Author

@mejrs mejrs May 5, 2022

Choose a reason for hiding this comment

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

Well, I'd like to see to it that it doesn't start compiling again. I guess it doesn't matter because it's so old. IMO this is one of these "don't waste time thinking about it, just do it" kind of things.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, though I might trim some of these back again another time if I ever try to optimise our CI pipeline. 👍

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.

Looks great to me, thanks as always for the many documentation improvements which I'm so poor at! 🫣

@@ -722,7 +722,7 @@ If `T` implements `Clone`, you can extract `T` itself.
In addition, you can also extract `&PyCell<T>`, though you rarely need it.

Before:
```ignore
```compile_fail
Copy link
Member

Choose a reason for hiding this comment

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

Ok, though I might trim some of these back again another time if I ever try to optimise our CI pipeline. 👍

@@ -311,7 +311,7 @@ from anywhere as long as your `app.py` is in the expected directory (in this exa
that directory is `/usr/share/python_app`).

`src/main.rs`:
```ignore
```no_run
Copy link
Member

Choose a reason for hiding this comment

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

I was just wondering whether the rust tag was also needed to give nice syntax highlighting.

@davidhewitt davidhewitt merged commit bc8641c into PyO3:main May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-no-fail-fast If one job fails, allow the rest to keep testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants