Message329202
| 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:24 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, yselivanov, pablogsal, Windson Yang, xtreak |
| 2018年11月03日 18:12:24 | serhiy.storchaka | set | messageid: <1541268744.84.0.788709270274.issue35113@psf.upfronthosting.co.za> |
| 2018年11月03日 18:12:24 | serhiy.storchaka | link | issue35113 messages |
| 2018年11月03日 18:12:24 | serhiy.storchaka | create |
|