Skip to content

Commit 3f01dc9

Browse files
jovenlin0527davidhewittbirkenfeld
authored
Apply suggestions from code review
Co-authored-by: David Hewitt <[email protected]> Co-authored-by: Georg Brandl <[email protected]>
1 parent d4bcaf5 commit 3f01dc9

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

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

2626
### Changed
2727

guide/src/class.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This chapter will discuss the functionality and configuration these attributes o
2020

2121
## Defining a new class
2222

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

@@ -144,8 +144,8 @@ so that they can benefit from a freelist. `XXX` is a number of items for the fre
144144
* `gc` - Classes with the `gc` parameter participate in Python garbage collection.
145145
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.
146146
* `weakref` - Adds support for Python weak references.
147-
* `extends=BaseType` - Use a custom base class. The base `BaseType` must implement `PyTypeInfo`. Enums can't have custom base class.
148-
* `subclass` - Allows Python classes to inherit from this class. Enums cannot be inherited.
147+
* `extends=BaseType` - Use a custom base class. The base `BaseType` must implement `PyTypeInfo`. `enum` pyclasses can't use a custom base class.
148+
* `subclass` - Allows Python classes to inherit from this class. `enum` pyclasses can't be inherited from.
149149
* `dict` - Adds `__dict__` support, so that the instances of this type have a dictionary containing arbitrary instance variables.
150150
* `unsendable` - Making it safe to expose `!Send` structs to Python, where all object can be accessed
151151
by multiple threads. A class marked with `unsendable` panics when accessed by another thread.

pyo3-macros-backend/src/pyclass.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,8 @@ struct PyClassEnumVariant<'a> {
383383

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

0 commit comments

Comments
 (0)