[issue37922] inspect.getsource returns wrong class definition when multiple class definitions share the same name (but are defined in different scopes)

2019-10-24 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Closing it as duplicate of issue35113.

--
nosy: +serhiy.storchaka
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> inspect.getsource returns incorrect source for classes when 
class definition is part of multiline strings
type:  -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37922] inspect.getsource returns wrong class definition when multiple class definitions share the same name (but are defined in different scopes)

2019-08-22 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

This looks like a duplicate of https://bugs.python.org/issue35113 . I have 
created a PR for the issue but didn't have time to debug the Windows issue.

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37922] inspect.getsource returns wrong class definition when multiple class definitions share the same name (but are defined in different scopes)

2019-08-22 Thread Caleb Donovick


Caleb Donovick  added the comment:

I think findsource could be made more robust by using __qualname__ if it 
available.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37922] inspect.getsource returns wrong class definition when multiple class definitions share the same name (but are defined in different scopes)

2019-08-22 Thread Caleb Donovick


Change by Caleb Donovick :


--
nosy: +donovick

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37922] inspect.getsource returns wrong class definition when multiple class definitions share the same name (but are defined in different scopes)

2019-08-22 Thread Leonard Truong


Leonard Truong  added the comment:

Turns out this is a documented issue in the source code: 
https://github.com/python/cpython/blob/3.7/Lib/inspect.py#L794-L796

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37922] inspect.getsource returns wrong class definition when multiple class definitions share the same name (but are defined in different scopes)

2019-08-22 Thread Leonard Truong

New submission from Leonard Truong :

Here's a case where `inspect.getsource` returns the wrong class definition when 
a file contains multiple class definitions with the same name. This pattern is 
valid runtime behavior when the class definitions are inside different scopes 
(e.g. a factory pattern where classes are defined and returned inside a 
function).

```
import inspect


def foo0():
class Foo:
x = 4
return Foo


def foo1():
class Foo:
x = 5
return Foo


print(inspect.getsource(foo1()))

print(foo1().x)
print(foo0().x)
```

Running this file produces
```
❯ python inspect-getsource-issue.py
class Foo:
x = 4

5
4
```

--
components: Library (Lib)
files: inspect-getsource-issue.py
messages: 350235
nosy: lennyt
priority: normal
severity: normal
status: open
title: inspect.getsource returns wrong class definition when multiple class 
definitions share the same name (but are defined in different scopes)
versions: Python 3.7
Added file: https://bugs.python.org/file48557/inspect-getsource-issue.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com