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

guide: add type overview #801

Merged
merged 3 commits into from
Mar 16, 2020
Merged

guide: add type overview #801

merged 3 commits into from
Mar 16, 2020

Conversation

birkenfeld
Copy link
Member

fixes #789

@birkenfeld
Copy link
Member Author

Obviously unfinished, but I'd like feedback if the style is ok...

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.

I like what you've written so far. Thanks so much for doing this. When I first came to pyo3 my head was totally boggled by all this too.

Is it also worth adding a note somewhere about references, e.g. that we must use &PyAny rather than PyAny (at least until improvements from #679 land)?

guide/src/types.md Outdated Show resolved Hide resolved
* explain: GIL lifetime
* explain: mutability?

## Smart pointers
Copy link
Member

Choose a reason for hiding this comment

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

It's worth noting (either for your own benefit, or as part of this section) that we (well, at least myself and @kngwyu) are hoping to one day merge PyAny and PyObject - Py<PyAny> is pretty much the same as PyObject.

See #679

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, that was one question I was going to pose to y'all :)

**Conversions:**

- To `&PyAny`: `.as_ref(py)`
- To `Py<ConcreteType>`: ???
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd like Py::new() to be able to do this one day, but that's a breaking API change.

**Conversions:**

- To `&PyAny`: `.as_ref(py)`
- To `Py<ConcreteType>`: ???
Copy link
Member

Choose a reason for hiding this comment

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

We can use obj.as_ref(py).extract::<Py<ConcreteType>>

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, that's good to know!

guide/src/types.md Outdated Show resolved Hide resolved
@kngwyu
Copy link
Member

kngwyu commented Mar 13, 2020

Thank you, it's really easy to read.
My concern is it lacks a section that explains how we should use native types(&PyDict, &PyList, or so).
And it would be good to explain that we allow mutable operations for &PyDict or so since it's really hard to track mutability of them

@birkenfeld
Copy link
Member Author

Thank you, it's really easy to read.
My concern is it lacks a section that explains how we should use native types(&PyDict, &PyList, or so).

What specifically do you have in mind here?

And it would be good to explain that we allow mutable operations for &PyDict or so since it's really hard to track mutability of them

OK, I'll try to find a spot to integrate this.

@kngwyu
Copy link
Member

kngwyu commented Mar 13, 2020

What specifically do you have in mind here?

Just like what you've added as ### PyTuple, PyDict, and many more.

birkenfeld and others added 2 commits March 13, 2020 15:14
fixes PyO3#789

Co-Authored-By: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Co-Authored-By: Yuji Kanagawa <yuji.kngw.80s.revive@gmail.com>
@birkenfeld birkenfeld marked this pull request as ready for review March 13, 2020 14:15
@birkenfeld birkenfeld changed the title [WIP] book: add type overview guide: add type overview Mar 13, 2020
guide/src/types.md Outdated Show resolved Hide resolved
guide/src/types.md Show resolved Hide resolved
@kngwyu
Copy link
Member

kngwyu commented Mar 16, 2020

Thank you!

@kngwyu kngwyu merged commit fa2e22b into PyO3:master Mar 16, 2020
@birkenfeld birkenfeld deleted the guide-types branch March 18, 2020 06:02
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.

Overview of pointer types and related traits
3 participants