Skip to content

Commit 2e70769

Browse files
committed
fix!: update README.rst, allow class definition in IDLE sessions, bump to v0.4.8
1 parent b71398b commit 2e70769

3 files changed

Lines changed: 54 additions & 3 deletions

File tree

README.rst

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

97129
Solving the multiple-inheritance and ``__slots__`` problem
98-
***************************************************************
130+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99131

100132
Consider the following graph::
101133

@@ -150,6 +182,25 @@ Callgraph Performance
150182
Benchmark
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+
153204
Before additions of coercion, event-listeners, multiple-inheritance
154205

155206
::

instruct/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def dummy(self):
279279
if current_closure is None:
280280
current_closure = ()
281281
new_globals = globals()
282-
if function.__module__ and function.__module__ != "__main__":
282+
if function.__module__:
283283
module = import_module(function.__module__)
284284
new_globals = module.__dict__
285285

instruct/about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.4.7"
1+
__version__ = "0.4.8"

0 commit comments

Comments
 (0)