@@ -91,11 +91,43 @@ And have it work like this?
9191 org.history()
9292
9393
94+ Example Usage
95+ ^^^^^^^^^^^^^^^
96+
97+ .. code-block :: pycon
98+
99+ >>> from instruct import Base
100+ >>>
101+ >>> class MyClass(Base):
102+ ... foo: int
103+ ... bar: Optional[str]
104+ ... baz: Union[Dict[str, str], int]
105+ ... def __eq__(self, other):
106+ ... if isinstance(other, tuple) and len(other) == 3:
107+ ... # Cast the tuple to this type!
108+ ... other = MyClass(*other)
109+ ... return super().__eq__(other)
110+ ...
111+ >>> instance = MyClass(1, None, baz={"a": "a"})
112+ >>> assert instance.foo == 1
113+ >>> assert instance.bar is None
114+ >>> instance.bar = "A String!"
115+ >>>
116+ >>> assert instance == (1, "A String!", {"a": "a"})
117+ >>>
118+ >>> instance.foo = 'I should not be allowed'
119+ Traceback (most recent call last):
120+ File "<stdin>", line 1, in <module>
121+ File "<getter-setter>", line 36, in _set_foo
122+ TypeError: Unable to set foo to 'I should not be allowed' (str). foo expects a int
123+ >>>
124+
125+
94126 Design
95127----------
96128
97129Solving the multiple-inheritance and ``__slots__ `` problem
98- ***************************************************************
130+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99131
100132Consider the following graph::
101133
@@ -150,6 +182,25 @@ Callgraph Performance
150182Benchmark
151183--------------
152184
185+
186+ Latest benchmark run:::
187+
188+ (python) Fateweaver:~/software/instruct [master]$ python --version
189+ Python 3.7.7
190+ (python) Fateweaver:~/software/instruct [master]$ python -m instruct benchmark
191+ Overhead of allocation, one field, safeties on: 19.53us
192+ Overhead of allocation, one field, safeties off: 19.50us
193+ Overhead of setting a field:
194+ Test with safeties: 0.27 us
195+ Test without safeties: 0.17 us
196+ Overhead of clearing/setting
197+ Test with safeties: 0.75 us
198+ Test without safeties: 0.65 us
199+ (python) Fateweaver:~/software/instruct [master]$
200+
201+
202+
203+
153204Before additions of coercion, event-listeners, multiple-inheritance
154205
155206::
0 commit comments