Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion poseur.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
16 changes: 16 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading