Skip to content

Commit

Permalink
[dpcs] Improve @dataclass example (#4866)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoSTEALTH committed May 5, 2024
1 parent a60d862 commit 34b485d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/examples/userguide/extension_types/dataclass.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ cdef class MyDataclass:
b: cython.double = dataclasses.field(default_factory = lambda: 10, repr=False)

# fields can also be declared using `cdef`:
cdef str c
cdef str c # add `readonly` or `public` to if `c` needs to be accessible from Python
c = "hello" # assignment of default value on a separate line
# note: `@dataclass(frozen)` is not enforced on `cdef` attributes

# typing.InitVar and typing.ClassVar also work
d: dataclasses.InitVar[cython.double] = 5
Expand Down

0 comments on commit 34b485d

Please sign in to comment.