|
1543 | 1543 | "output_type": "stream",
|
1544 | 1544 | "text": [
|
1545 | 1545 | "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", |
1547 | 1547 | " try: return _run(code, glb, loc)\n",
|
1548 | 1548 | " ^^^^^^^^^^^^^^^^^^^^\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", |
1550 | 1550 | " try: exec(compiled_code, glb, loc)\n",
|
1551 | 1551 | " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
|
1552 | 1552 | " 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", |
1554 | 1554 | " def handler(*args): raise TimeoutError()\n",
|
1555 | 1555 | " ^^^^^^^^^^^^^^^^^^^^\n",
|
1556 | 1556 | "TimeoutError\n",
|
|
1691 | 1691 | " merged = {}\n",
|
1692 | 1692 | " for o in listify(fs):\n",
|
1693 | 1693 | " 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", |
1695 | 1694 | " 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", |
1697 | 1695 | " return merged"
|
1698 | 1696 | ]
|
1699 | 1697 | },
|
|
1740 | 1738 | "ns['sums'](1, 2)"
|
1741 | 1739 | ]
|
1742 | 1740 | },
|
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 |
| - }, |
1871 | 1741 | {
|
1872 | 1742 | "cell_type": "code",
|
1873 | 1743 | "execution_count": null,
|
|
1920 | 1790 | {
|
1921 | 1791 | "cell_type": "code",
|
1922 | 1792 | "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", |
1945 | 1794 | "metadata": {},
|
1946 | 1795 | "outputs": [],
|
1947 | 1796 | "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)" |
1949 | 1798 | ]
|
1950 | 1799 | },
|
1951 | 1800 | {
|
|
1955 | 1804 | "metadata": {},
|
1956 | 1805 | "outputs": [],
|
1957 | 1806 | "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})" |
1959 | 1808 | ]
|
1960 | 1809 | },
|
1961 | 1810 | {
|
|
0 commit comments