You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/language/classes.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@ title: "Classes"
3
3
description: "User-defined classes as state machines and library namespaces."
4
4
---
5
5
6
-
Edge Python is functional-first, classes are state containers and namespaces, not the primary abstraction. Two patterns: state machines (a few methods that mutate the receiver) and namespaces (a bundle of related functions and constants).
6
+
Where classes are state containers and namespaces, not the primary abstraction (decided by design for the compiler purpose). Two patterns: state machines (a few methods that mutate the receiver) and namespaces (a bundle of related functions and constants).
7
7
8
-
Single-level inheritance with `super()`, `@property` / `@x.setter`, full dunder protocol for operators, indexing, iteration, context managers (see [Dunder methods](/language/dunders)). Multi-base C3 MRO, descriptors, metaclasses, `__slots__` are out of scope.
8
+
Single-level inheritance with `super()`, `@property` / `@x.setter`, and a curated dunder protocol covering operators, indexing, iteration, hashing, context managers, and attribute fallback (see [Dunder methods](/language/dunders)). Multi-base C3 MRO, descriptors, metaclasses, `__slots__` are out of scope.
9
9
10
10
## State-machine pattern
11
11
@@ -31,7 +31,7 @@ print(c.value())
31
31
32
32
## Namespace pattern
33
33
34
-
A class with no `__init__` and no per-instance state is a namespace. Methods called on the class are unbound, no `self` prepended.
34
+
A class with no `__init__` and no per-instance state is a namespace. Methods called on the class are unbound — no `self` prepended.
35
35
36
36
```python
37
37
classStatus:
@@ -61,7 +61,7 @@ print(Math.cube(3))
61
61
62
62
## Inheritance and super()
63
63
64
-
Single base via `class Sub(Base):`. Methods not on the subclass are looked up linearly on the base, no C3 MRO. `isinstance(x, Base)` walks the same chain, so `Sub` instances are also instances of every ancestor.
64
+
Single base via `class Sub(Base):`. Methods not on the subclass are looked up linearly on the base — no C3 MRO. `isinstance(x, Base)` walks the same chain, so `Sub` instances are also instances of every ancestor.
65
65
66
66
`super()` (zero-arg) delegates to the next class up the chain, bound to current `self`. Most common in `__init__` to extend a base constructor.
67
67
@@ -102,7 +102,7 @@ True
102
102
103
103
## Class decorators
104
104
105
-
A class decorator wraps the class object the same way it wraps a function, the decorator is called with the class; its return binds to the name.
105
+
A class decorator wraps the class object the same way it wraps a function — the decorator is called with the class; its return binds to the name.
106
106
107
107
```python
108
108
deftag(cls):
@@ -125,7 +125,7 @@ tagged
125
125
126
126
## Properties
127
127
128
-
`@property` turns a method into a read-only attribute. `@x.setter` (via `property.setter`) makes it writable. Properties live on the class, subclasses inherit and can override either side.
128
+
`@property` turns a method into a read-only attribute. `@x.setter` (via `property.setter`) makes it writable. Properties live on the class; subclasses inherit and can override either side.
129
129
130
130
```python
131
131
classTemp:
@@ -174,7 +174,7 @@ See [Dunder methods](/language/dunders) for the full matrix.
174
174
175
175
* Multi-base inheritance with proper C3 MRO. `class C(A, B):` parses and both bases are stored, but resolution is a linear depth-first walk, not C3. Prefer single inheritance.
*`@staticmethod` / `@classmethod`, use the namespace pattern or free functions.
178
-
* Async dunders, see [Dunders, What's not dispatched](/language/dunders#whats-not-dispatched).
177
+
*`@staticmethod` / `@classmethod` — use the namespace pattern or free functions.
178
+
* Async dunders; see [Dunders, What's not dispatched](/language/dunders#whats-not-dispatched).
179
179
180
-
Behaviour reuse via free functions and composition remains the default, fast dispatch, aligned with the functional-first identity. Reach for inheritance and operator overloading when the abstraction genuinely calls for them.
180
+
Behaviour reuse via free functions and composition remains the default — fast dispatch, aligned with the functional-first identity. Reach for inheritance and operator overloading when the abstraction genuinely calls for them.
0 commit comments