|
1584 | 1584 | " if store_args is None: store_args = not hasattr(self,'__slots__')\n", |
1585 | 1585 | " if store_args and not hasattr(self, '__stored_args__'): self.__stored_args__ = {}\n", |
1586 | 1586 | " anno = annotations(self) if cast else {}\n", |
1587 | | - " if not attrs:\n", |
1588 | | - " if names and isinstance(names,str): names = re.split(', *', names)\n", |
1589 | | - " ns = names if names else getattr(self, '__slots__', args[1:])\n", |
1590 | | - " attrs = {n:fr.f_locals[n] for n in ns}\n", |
| 1587 | + " if names and isinstance(names,str): names = re.split(', *', names)\n", |
| 1588 | + " ns = names if names else getattr(self, '__slots__', args[1:])\n", |
| 1589 | + " added = {n:fr.f_locals[n] for n in ns}\n", |
| 1590 | + " attrs = {**attrs, **added}\n", |
1591 | 1591 | " if isinstance(but,str): but = re.split(', *', but)\n", |
1592 | 1592 | " attrs = {k:v for k,v in attrs.items() if k not in but}\n", |
1593 | 1593 | " return _store_attr(self, anno, **attrs)" |
|
1811 | 1811 | "assert t.a==1 and t.b==3 and t.c==2" |
1812 | 1812 | ] |
1813 | 1813 | }, |
| 1814 | + { |
| 1815 | + "cell_type": "code", |
| 1816 | + "execution_count": null, |
| 1817 | + "metadata": {}, |
| 1818 | + "outputs": [], |
| 1819 | + "source": [ |
| 1820 | + "#hide\n", |
| 1821 | + "#ensure that kwargs work with names==None\n", |
| 1822 | + "class T:\n", |
| 1823 | + " def __init__(self, a,b,c,**kwargs): store_attr(**kwargs)\n", |
| 1824 | + "\n", |
| 1825 | + "t = T(1,c=2,b=3,d=4,e=-1)\n", |
| 1826 | + "assert t.a==1 and t.b==3 and t.c==2 and t.d==4 and t.e==-1" |
| 1827 | + ] |
| 1828 | + }, |
1814 | 1829 | { |
1815 | 1830 | "cell_type": "markdown", |
1816 | 1831 | "metadata": {}, |
|
0 commit comments