diff --git a/poseur.py b/poseur.py index d1bbda7..a08d0b7 100644 --- a/poseur.py +++ b/poseur.py @@ -741,7 +741,7 @@ def _process_classdef(self, node: parso.python.tree.Class) -> None: # PythonNode(suite, [...]) / PythonNode(simple_stmt, [...]) suite = node.children[-1] - self._process_suite_node(suite, cls_ctx=name.name) + self._process_suite_node(suite, cls_ctx=name.value) def _process_if_stmt(self, node: parso.python.tree.IfStmt) -> None: """Process if statement (:token:`if_stmt`). diff --git a/tests/test.py b/tests/test.py index 6337b54..5c20e81 100644 --- a/tests/test.py +++ b/tests/test.py @@ -209,6 +209,22 @@ def test_funcdef(self): POSEUR_LINESEP.join(_decorator) % dict(decorator='_poseur_decorator', indentation='\t'.expandtabs(4))).lstrip() self._check_convert(src, dst) + def test_classdef(self): + # no poseur + src = 'class Cls:\n def func(self): pass' + dst = 'class Cls:\n def func(self): pass' + self._check_convert(src, dst) + + # poseur on a method -- this used to raise AttributeError from + # ``_process_classdef`` and leave the source unconverted, and because + # ``bpc_utils`` swallows the exception per node the process still exited 0 + self.assertNotIn(', /', convert('class Cls:\n def func(self, a, /, b): pass')) + + src = 'class Cls:\n def func(self, a, /, b): pass' + dst = "%s\n\n\nclass Cls:\n @_poseur_decorator('self', 'a')\n def func(self, a, b): pass" % ( + POSEUR_LINESEP.join(_decorator) % dict(decorator='_poseur_decorator', indentation='\t'.expandtabs(4))).lstrip() + self._check_convert(src, dst) + if __name__ == '__main__': unittest.main()