Skip to content

Commit 0370f33

Browse files
author
Sylvain MARIE
committed
Updated documentation.
1 parent 9bd6361 commit 0370f33

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/index.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,22 @@ post init ! height=1, color=white, msg=hey
428428
Note on the order of arguments in the resulting `__init__` signature: as you can see, `msg` appears between `height` and `color` in the signature. This corresponds to the
429429

430430

431+
### 3. Misc.
432+
433+
#### Slots
434+
435+
You can use `pyfields` if your class has `__slots__`. You will simply have to use an underscore in the slot name corresponding to a field: `_<field_name>`. For example:
436+
437+
```python
438+
class WithSlots(object):
439+
__slots__ = ('_a',)
440+
a = field()
441+
```
442+
443+
Since from [python documentation](https://docs.python.org/3/reference/datamodel.html#slots), *"class attributes cannot be used to set default values for instance variables defined by `__slots__`"*, **native fields are not supported with `__slots__`**. If you run python `3.6` or greater, `field` will automatically detect that a field is used on a class with `__slots__` and will replace the native field with a descriptor field. However with older python versions this is not always possible, so it is recommended that you explicitly state `native=False`.
444+
445+
Note that if your class is a dual class (meaning that it declares a slot named `__dict__`), then **native fields are supported** and you do not have anything special to do (not even declaring a slot for the field).
446+
431447
## Main features / benefits
432448

433449
**TODO**

0 commit comments

Comments
 (0)