[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2021-07-13 Thread Łukasz Langa
Łukasz Langa added the comment: New changeset d4a5f0b659a2b8f206cfbdfd37fc36aedf77a71f by andrei kulakov in branch 'main': bpo-35113: clean up duplicate import and comment (#27073) https://github.com/python/cpython/commit/d4a5f0b659a2b8f206cfbdfd37fc36aedf77a71f -- nosy:

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2021-07-13 Thread Andrei Kulakov
Change by Andrei Kulakov : -- nosy: +andrei.avk nosy_count: 6.0 -> 7.0 pull_requests: +25656 pull_request: https://github.com/python/cpython/pull/27073 ___ Python tracker ___

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2020-04-28 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Closing this as fixed with the enhancement to show decorator for classes too for 3.9. Thank you all for the help on this. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: +Python 3.9 -Python 3.6,

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2020-04-18 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- pull_requests: +18924 pull_request: https://github.com/python/cpython/pull/19587 ___ Python tracker ___

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2020-04-18 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: New changeset 696136b993e11b37c4f34d729a0375e5ad544ade by Karthikeyan Singaravelan in branch 'master': bpo-35113: Fix inspect.getsource to return correct source for inner classes (#10307)

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2019-10-24 Thread Caleb Donovick
Change by Caleb Donovick : -- nosy: +donovick ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Yury, could you please take a look? -- ___ Python tracker ___ ___ Python-bugs-list mailing

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: As for the line number for class, I have not heard anything about this. I think there is no large technical difficulty, but there is a little need. The first line number of the code object is needed first at all for tracing and debugging. Function has

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Thanks Serhiy for the details. I think there are also less tests for inspect.findsource with respect to classes though it's more robust than the regex approach. Thus there might be different effects which are correct now or selects an alternate

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: 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

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- keywords: +patch pull_requests: +9614 stage: -> patch review ___ Python tracker ___ ___

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Thanks Serhiy, I am going with the same approach too using a Stack. I am working on it and I have fixed the set initial cases I reported with tests. I just stumbled upon the nested definitions and inner classes. I will raise a PR by end of today

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Use a stack of names. Every time when you enter a class and function nodes, push the current name on the stack, and pop it out after handling child nodes. Compare the qualified name with '.'.join(self.stack). Don't use the recursive decorator, it is not

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Thanks Serhiy, object.__qualname__ can be used to get qualified name of the object but ast nodes don't have qualified name for the node where I can match against it. node.name returns unqualified name and hence using ast module I can't

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Use __qualname__. -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-03 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I tried ast module and it passes my test cases but I found another case since object.__name__ returns unqualified name thus matching against nested class names might conflict with the ones on the top level. Example is below where there is Spam at

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-02 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I think parsing with regex especially on multiline cases like here is little tricky handling all cases. I find AST module to be a good fit. I tried using a callback where every class definition is taken up and then from that line to rest of the

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-11-01 Thread Windson Yang
Windson Yang added the comment: Yes, the code located at https://github.com/python/cpython/blob/7cd25434164882c2093ea41ccfc7b95a05cd5cbd/Lib/inspect.py#L794 I think to use a comment status var would be a solution, Do you have any idea to fix it? -- nosy: +Windson Yang

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-10-31 Thread Pablo Galindo Salgado
Change by Pablo Galindo Salgado : -- nosy: +pablogsal ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue35113] inspect.getsource returns incorrect source for classes when class definition is part of multiline strings

2018-10-30 Thread Karthikeyan Singaravelan
New submission from Karthikeyan Singaravelan : inspect.getsource uses inspect.findsource that uses a regex to check for class declaration and starts matching against the regex from the start of the program. When there is a match it checks for the first character to be 'c' to return the line