Skip to content

Commit 3e689a7

Browse files
committed
fixes #35
1 parent 3006b7a commit 3e689a7

File tree

5 files changed

+13
-161
lines changed

5 files changed

+13
-161
lines changed

01_funccall.ipynb

Lines changed: 6 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,14 +1543,14 @@
15431543
"output_type": "stream",
15441544
"text": [
15451545
"Traceback (most recent call last):\n",
1546-
" File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_88095/2052945749.py\", line 14, in python\n",
1546+
" File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_10039/2052945749.py\", line 14, in python\n",
15471547
" try: return _run(code, glb, loc)\n",
15481548
" ^^^^^^^^^^^^^^^^^^^^\n",
1549-
" File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_88095/1858893181.py\", line 18, in _run\n",
1549+
" File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_10039/1858893181.py\", line 18, in _run\n",
15501550
" try: exec(compiled_code, glb, loc)\n",
15511551
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
15521552
" File \"<ast>\", line 1, in <module>\n",
1553-
" File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_88095/2052945749.py\", line 9, in handler\n",
1553+
" File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_10039/2052945749.py\", line 9, in handler\n",
15541554
" def handler(*args): raise TimeoutError()\n",
15551555
" ^^^^^^^^^^^^^^^^^^^^\n",
15561556
"TimeoutError\n",
@@ -1691,9 +1691,7 @@
16911691
" merged = {}\n",
16921692
" for o in listify(fs):\n",
16931693
" if isinstance(o, dict): merged |= o\n",
1694-
" elif isinstance(o, type): merged |= {n:getattr(o,n) for n,m in o.__dict__.items() if isinstance(m, (staticmethod, classmethod))}\n",
16951694
" elif callable(o) and hasattr(o, '__name__'): merged |= {o.__name__: o}\n",
1696-
" merged |= {n:getattr(o,n) for n, m in inspect.getmembers(o, inspect.ismethod)} | {n:m for n,m in o.__class__.__dict__.items() if isinstance(m, staticmethod)}\n",
16971695
" return merged"
16981696
]
16991697
},
@@ -1740,134 +1738,6 @@
17401738
"ns['sums'](1, 2)"
17411739
]
17421740
},
1743-
{
1744-
"cell_type": "code",
1745-
"execution_count": null,
1746-
"id": "29d22f82",
1747-
"metadata": {},
1748-
"outputs": [],
1749-
"source": [
1750-
"class Dummy:\n",
1751-
" def __init__(self,a): self.a = a\n",
1752-
" def __call__(self): return self.a\n",
1753-
" def sums(self, a, b): return a + b\n",
1754-
" @staticmethod\n",
1755-
" def subs(a, b): return a - b\n",
1756-
" @classmethod\n",
1757-
" def mults(cls, a, b): return a * b"
1758-
]
1759-
},
1760-
{
1761-
"cell_type": "code",
1762-
"execution_count": null,
1763-
"id": "ca50b957",
1764-
"metadata": {},
1765-
"outputs": [
1766-
{
1767-
"data": {
1768-
"text/plain": [
1769-
"{'subs': <function __main__.Dummy.subs(a, b)>,\n",
1770-
" 'mults': <bound method Dummy.mults of <class '__main__.Dummy'>>}"
1771-
]
1772-
},
1773-
"execution_count": null,
1774-
"metadata": {},
1775-
"output_type": "execute_result"
1776-
}
1777-
],
1778-
"source": [
1779-
"ns = mk_ns(Dummy); ns"
1780-
]
1781-
},
1782-
{
1783-
"cell_type": "code",
1784-
"execution_count": null,
1785-
"id": "59ef734f",
1786-
"metadata": {},
1787-
"outputs": [
1788-
{
1789-
"data": {
1790-
"text/plain": [
1791-
"(-1, 6)"
1792-
]
1793-
},
1794-
"execution_count": null,
1795-
"metadata": {},
1796-
"output_type": "execute_result"
1797-
}
1798-
],
1799-
"source": [
1800-
"ns['subs'](1, 2), ns['mults'](3, 2)"
1801-
]
1802-
},
1803-
{
1804-
"cell_type": "code",
1805-
"execution_count": null,
1806-
"id": "15871e6d",
1807-
"metadata": {},
1808-
"outputs": [
1809-
{
1810-
"data": {
1811-
"text/plain": [
1812-
"{'__call__': <bound method Dummy.__call__ of <__main__.Dummy object>>,\n",
1813-
" '__init__': <bound method Dummy.__init__ of <__main__.Dummy object>>,\n",
1814-
" 'mults': <bound method Dummy.mults of <class '__main__.Dummy'>>,\n",
1815-
" 'sums': <bound method Dummy.sums of <__main__.Dummy object>>,\n",
1816-
" 'subs': <staticmethod(<function Dummy.subs>)>}"
1817-
]
1818-
},
1819-
"execution_count": null,
1820-
"metadata": {},
1821-
"output_type": "execute_result"
1822-
}
1823-
],
1824-
"source": [
1825-
"d = Dummy(10)\n",
1826-
"ns = mk_ns(d); ns"
1827-
]
1828-
},
1829-
{
1830-
"cell_type": "code",
1831-
"execution_count": null,
1832-
"id": "13cb7685",
1833-
"metadata": {},
1834-
"outputs": [
1835-
{
1836-
"data": {
1837-
"text/plain": [
1838-
"(-1, 6, 5, 10)"
1839-
]
1840-
},
1841-
"execution_count": null,
1842-
"metadata": {},
1843-
"output_type": "execute_result"
1844-
}
1845-
],
1846-
"source": [
1847-
"ns['subs'](1, 2), ns['mults'](3, 2), ns['sums'](3, 2), ns['__call__']()"
1848-
]
1849-
},
1850-
{
1851-
"cell_type": "code",
1852-
"execution_count": null,
1853-
"id": "2dfe13ae",
1854-
"metadata": {},
1855-
"outputs": [
1856-
{
1857-
"data": {
1858-
"text/plain": [
1859-
"(None, -99)"
1860-
]
1861-
},
1862-
"execution_count": null,
1863-
"metadata": {},
1864-
"output_type": "execute_result"
1865-
}
1866-
],
1867-
"source": [
1868-
"ns['__init__'](-99), ns['__call__']()"
1869-
]
1870-
},
18711741
{
18721742
"cell_type": "code",
18731743
"execution_count": null,
@@ -1920,32 +1790,11 @@
19201790
{
19211791
"cell_type": "code",
19221792
"execution_count": null,
1923-
"id": "9aace64a",
1924-
"metadata": {},
1925-
"outputs": [
1926-
{
1927-
"data": {
1928-
"text/plain": [
1929-
"-1"
1930-
]
1931-
},
1932-
"execution_count": null,
1933-
"metadata": {},
1934-
"output_type": "execute_result"
1935-
}
1936-
],
1937-
"source": [
1938-
"call_func('subs', {'a': 1, 'b': 2}, ns=mk_ns(d))"
1939-
]
1940-
},
1941-
{
1942-
"cell_type": "code",
1943-
"execution_count": null,
1944-
"id": "6c93c0ef",
1793+
"id": "3c638361",
19451794
"metadata": {},
19461795
"outputs": [],
19471796
"source": [
1948-
"assert \"unsupported operand type(s) for -: 'int' and 'str'\" in call_func('subs', {'a': 1, 'b': '3'}, ns=mk_ns(d), raise_on_err=False)"
1797+
"assert \"unsupported operand type(s) for +: 'int' and 'str'\" in call_func('sums', {'a': 1, 'b': '3'}, ns=ns, raise_on_err=False)"
19491798
]
19501799
},
19511800
{
@@ -1955,7 +1804,7 @@
19551804
"metadata": {},
19561805
"outputs": [],
19571806
"source": [
1958-
"test_fail(call_func, args=['subs', {'a': 1, 'b': '3'}], kwargs={'ns': mk_ns(d)})"
1807+
"test_fail(call_func, args=['sums', {'a': 1, 'b': '3'}], kwargs={'ns': ns})"
19591808
]
19601809
},
19611810
{

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
<!-- do not remove -->
44

5+
## 0.3.0
6+
7+
8+
9+
510
## 0.2.3
611

712
### New Features

settings.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[DEFAULT]
22
repo = toolslm
33
lib_name = toolslm
4-
version = 0.2.4
4+
version = 0.3.0
55
min_python = 3.9
66
license = apache2
77
black_formatting = False

toolslm/__init__.py

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

toolslm/funccall.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ def mk_ns(fs):
188188
merged = {}
189189
for o in listify(fs):
190190
if isinstance(o, dict): merged |= o
191-
elif isinstance(o, type): merged |= {n:getattr(o,n) for n,m in o.__dict__.items() if isinstance(m, (staticmethod, classmethod))}
192191
elif callable(o) and hasattr(o, '__name__'): merged |= {o.__name__: o}
193-
merged |= {n:getattr(o,n) for n, m in inspect.getmembers(o, inspect.ismethod)} | {n:m for n,m in o.__class__.__dict__.items() if isinstance(m, staticmethod)}
194192
return merged
195193

196194
# %% ../01_funccall.ipynb

0 commit comments

Comments
 (0)