[issue24078] inspect.getsourcelines ignores context and returns wrong line #

2020-09-18 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Thanks iritkatriel for triaging. I can confirm it's fixed with the linked 
issue. Closing it as duplicate.

./python
Python 3.10.0a0 (heads/master:2b05361bf7, Sep 19 2020, 04:38:05) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect, a
>>> inspect.getsourcelines(a.C.B)
(['class B(object):\n', 'pass\n'], 6)

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

___
Python tracker 

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



[issue24078] inspect.getsourcelines ignores context and returns wrong line #

2020-09-18 Thread Irit Katriel


Irit Katriel  added the comment:

I think this was fixed under issue35113.

--
nosy: +iritkatriel, xtreak

___
Python tracker 

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



[issue24078] inspect.getsourcelines ignores context and returns wrong line #

2015-05-08 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
nosy: +rhettinger

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



[issue24078] inspect.getsourcelines ignores context and returns wrong line #

2015-05-01 Thread James Edwards

Changes by James Edwards jh...@jheiv.com:


--
nosy: +pitrou, yselivanov

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



[issue24078] inspect.getsourcelines ignores context and returns wrong line #

2015-05-01 Thread James Edwards

James Edwards added the comment:

Added Yury (inspect module) and Antoine (PEP 3155) to nosy -- apologies  if 
you're not interested.

--

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



[issue24078] inspect.getsourcelines ignores context and returns wrong line #

2015-05-01 Thread James Edwards

James Edwards added the comment:

Inspect could probably be updated to use 3.3's __qualname__ in the case of 
classes-in-classes; classes-in-functions or functions-in-functions would likely 
be harder, but I'm not sure it's impossible.

--
nosy: +jedwards

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



[issue24078] inspect.getsourcelines ignores context and returns wrong line #

2015-04-29 Thread Siming Yuan

Siming Yuan added the comment:

according to inspect.py line 675 - this is only a best effort.

is this intended?

inspect.py @ 672
if isclass(object):
name = object.__name__
pat = re.compile(r'^(\s*)class\s*' + name + r'\b')
# make some effort to find the best matching class definition:
# use the one with the least indentation, which is the one
# that's most probably not inside a function definition.
candidates = []
for i in range(len(lines)):
match = pat.match(lines[i])
if match:
# if it's at toplevel, it's already the best one
if lines[i][0] == 'c':
return lines, i
# else add whitespace to candidate list
candidates.append((match.group(1), i))
if candidates:
# this will sort by whitespace, and by line number,
# less whitespace first
candidates.sort()
return lines, candidates[0][1]
else:
raise OSError('could not find class definition')

--

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



[issue24078] inspect.getsourcelines ignores context and returns wrong line #

2015-04-29 Thread Siming Yuan

New submission from Siming Yuan:

if the same class name is used within a module, but defined in different 
contexts (either class in class or class in function), inspect.getsourcelines() 
on the class object ignores the object context and only returns the first 
matched name.

reproduce:

a.py

class A(object):
class B(object):
pass

class C(object):
class B(object):
pass

--
 import inspect
 import a
 inspect.getsourcelines(a.C.B)
(['class B(object):\n', 'pass\n'], 2)

--
components: Library (Lib)
messages: 242254
nosy: siyuan
priority: normal
severity: normal
status: open
title: inspect.getsourcelines ignores context and returns wrong line #
type: behavior
versions: Python 3.4

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