This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Windson Yang, pablogsal, serhiy.storchaka, xtreak, yselivanov
Date 2018-11-03.18:12:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541268744.84.0.788709270274.issue35113@psf.upfronthosting.co.za>
In-reply-to
Content
Well, now the hardest problem remains.

Sometimes there are more than one place where the class with the same __qualname__ is defined. See for example multiprocessing/heap.py:

if sys.platform == 'win32':
    class Arena(object):
        ...
else:
    class Arena(object):
        ...

It is hard to determine the correct place. But the current code return the first line, while PR 10307 currently returns the last line.

If the current behavior is more desirable, the code needs to stop searching after finding the first candidate. And the simplest way is to use exceptions:

class ClassVisitor(ast.NodeVisitor):
    def visit_ClassDef(self, node):
        ...
        if found:
            raise StopIterator(line_number)
        ...
...
try:
    class_visitor.visit(tree)
except StopIterator as e:
    line_number = e.value
else:
    raise OSError('could not find class definition')
History
Date User Action Args
2018-11-03 18:12:24serhiy.storchakasetrecipients: + serhiy.storchaka, yselivanov, pablogsal, Windson Yang, xtreak
2018-11-03 18:12:24serhiy.storchakasetmessageid: <1541268744.84.0.788709270274.issue35113@psf.upfronthosting.co.za>
2018-11-03 18:12:24serhiy.storchakalinkissue35113 messages
2018-11-03 18:12:24serhiy.storchakacreate