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.

classification
Title: inspect.getsource() examines incorrect target
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: duplicate
Dependencies: Superseder: inspect.getsource returns incorrect source for classes when class definition is part of multiline strings
View: 35113
Assigned To: Nosy List: Grzegorz Krasoń, ammar2, xtreak
Priority: normal Keywords:

Created on 2020-04-18 11:50 by Grzegorz Krasoń, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
demo.py Grzegorz Krasoń, 2020-04-18 11:50 Example
Messages (5)
msg366701 - (view) Author: Grzegorz Krasoń (Grzegorz Krasoń) Date: 2020-04-18 11:50
Based on the attached example:

Expected output:
```
123
    class Number:
        payload = 123

321
    class Number:
        payload = 321
```

Actual output:
```
123
    class Number:
        payload = 123

321
    class Number:
        payload = 123
```

Reproduced using:

* Python 2.7.17
* Python 3.7.7
* Python 3.8.2
msg366719 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-04-18 14:30
This will be resolved hopefully resolved using https://github.com/python/cpython/pull/10307 . Using my patch on the reproducer in the report.

./python bpo40317.py
123
    class Number:
        payload = 123

321
    class Number:
        payload = 321
msg366728 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-04-18 16:34
Fixed in master now with https://github.com/python/cpython/commit/696136b993e11b37c4f34d729a0375e5ad544ade . This includes the change of show decorators for classes too to make it consistent with functions so it's not backported.
msg367579 - (view) Author: Ammar Askar (ammar2) * (Python committer) Date: 2020-04-28 23:52
Did you mean to close this Karthik?
msg367619 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2020-04-29 03:37
yes, thanks Ammar. Thanks Grzegorz for the report.
History
Date User Action Args
2022-04-11 14:59:29adminsetgithub: 84497
2020-04-29 03:37:05xtreaksetstatus: open -> closed
versions: + Python 3.9, - Python 2.7, Python 3.7, Python 3.8
superseder: inspect.getsource returns incorrect source for classes when class definition is part of multiline strings
messages: + msg367619

resolution: duplicate
stage: resolved
2020-04-28 23:52:00ammar2setnosy: + ammar2
messages: + msg367579
2020-04-18 16:34:05xtreaksetmessages: + msg366728
2020-04-18 14:30:24xtreaksetnosy: + xtreak
messages: + msg366719
2020-04-18 11:50:37Grzegorz Krasońcreate