Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
Co-authored-by: Georg Brandl <georg@python.org>
  • Loading branch information
3 people authored Dec 10, 2021
1 parent d4bcaf5 commit 3f01dc9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add `Py::setattr` method. [#2009](https://github.com/PyO3/pyo3/pull/2009)
- Add `PyCapsule`, exposing the [Capsule API](https://docs.python.org/3/c-api/capsule.html#capsules). [#1980](https://github.com/PyO3/pyo3/pull/1980)
- `#[pyclass]` now supports fieldless enums. It also provide default implementation for `__repr__`, `__int__`, and `__richcmp__` for enums.
- Enable `#[pyclass]` for fieldless (aka C-like) enums. [#2034](https://github.com/PyO3/pyo3/pull/2034)

### Changed

Expand Down
8 changes: 4 additions & 4 deletions guide/src/class.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This chapter will discuss the functionality and configuration these attributes o

## Defining a new class

To define a custom Python class, add `#[pyclass]` attribute to a Rust struct or a fieldless enum.
To define a custom Python class, add the `#[pyclass]` attribute to a Rust struct or a fieldless enum.
```rust
# #![allow(dead_code)]
# use pyo3::prelude::*;
Expand All @@ -33,7 +33,7 @@ struct MyClass {
#[pyclass]
enum MyEnum {
Variant,
OtherVariant = 30, // support custom discriminant.
OtherVariant = 30, // PyO3 supports custom discriminants.
}
```

Expand Down Expand Up @@ -144,8 +144,8 @@ so that they can benefit from a freelist. `XXX` is a number of items for the fre
* `gc` - Classes with the `gc` parameter participate in Python garbage collection.
If a custom class contains references to other Python objects that can be collected, the [`PyGCProtocol`]({{#PYO3_DOCS_URL}}/pyo3/class/gc/trait.PyGCProtocol.html) trait has to be implemented.
* `weakref` - Adds support for Python weak references.
* `extends=BaseType` - Use a custom base class. The base `BaseType` must implement `PyTypeInfo`. Enums can't have custom base class.
* `subclass` - Allows Python classes to inherit from this class. Enums cannot be inherited.
* `extends=BaseType` - Use a custom base class. The base `BaseType` must implement `PyTypeInfo`. `enum` pyclasses can't use a custom base class.
* `subclass` - Allows Python classes to inherit from this class. `enum` pyclasses can't be inherited from.
* `dict` - Adds `__dict__` support, so that the instances of this type have a dictionary containing arbitrary instance variables.
* `unsendable` - Making it safe to expose `!Send` structs to Python, where all object can be accessed
by multiple threads. A class marked with `unsendable` panics when accessed by another thread.
Expand Down
5 changes: 2 additions & 3 deletions pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,8 @@ struct PyClassEnumVariant<'a> {

struct PyClassEnum<'a> {
ident: &'a syn::Ident,
// The underyling representation of the enum.
// It's used to implement __int__ and __richcmp__.
// This matters when the underyling representation may not fit in `isize`.
// The underlying #[repr] of the enum, used to implement __int__ and __richcmp__.
// This matters when the underlying representation may not fit in `isize`.
repr: syn::Ident,
variants: Vec<PyClassEnumVariant<'a>>,
doc: PythonDoc,
Expand Down

0 comments on commit 3f01dc9

Please sign in to comment.