-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-35113: Fix inspect.getsource to return correct source for inner classes #10307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
51aa209
341933d
dbbb38e
22b9c9c
2655b1d
bd51f49
558895f
7d99c19
5f84344
8a63f36
4c7a61b
30865f6
054c317
26d1c96
d7ae710
aef4228
797c48d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -138,18 +138,124 @@ def func137(): | |
never_reached1 | ||
never_reached2 | ||
|
||
#line 141 | ||
# line 141 | ||
class cls142: | ||
a = """ | ||
class cls149: | ||
... | ||
""" | ||
|
||
# line 148 | ||
class cls149: | ||
|
||
def func151(self): | ||
pass | ||
|
||
''' | ||
class cls160: | ||
pass | ||
''' | ||
|
||
# line 159 | ||
class cls160: | ||
|
||
def func162(self): | ||
pass | ||
|
||
# line 165 | ||
class cls166: | ||
a = ''' | ||
class cls175: | ||
... | ||
''' | ||
|
||
# line 172 | ||
class cls173: | ||
|
||
class cls175: | ||
pass | ||
|
||
# line 178 | ||
class cls179: | ||
pass | ||
|
||
# line 182 | ||
class cls183: | ||
|
||
class cls185: | ||
|
||
def func186(self): | ||
pass | ||
|
||
def class_decorator(cls): | ||
return cls | ||
|
||
# line 193 | ||
@class_decorator | ||
@class_decorator | ||
class cls196: | ||
|
||
@class_decorator | ||
@class_decorator | ||
class cls200: | ||
pass | ||
|
||
class cls203: | ||
class cls204: | ||
class cls205: | ||
pass | ||
class cls207: | ||
class cls205: | ||
pass | ||
|
||
# line 211 | ||
def func212(): | ||
class cls213: | ||
pass | ||
return cls213 | ||
|
||
# line 217 | ||
class cls213: | ||
def func219(self): | ||
class cls220: | ||
pass | ||
return cls220 | ||
|
||
# line 224 | ||
async def func225(): | ||
class cls226: | ||
pass | ||
return cls226 | ||
|
||
# line 230 | ||
class cls226: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as my above comment but this is to check for This to check that the inner class which has the same name |
||
async def func232(self): | ||
class cls233: | ||
pass | ||
return cls233 | ||
|
||
if True: | ||
class cls238: | ||
class cls239: | ||
'''if clause cls239''' | ||
else: | ||
class cls238: | ||
class cls239: | ||
'''else clause 239''' | ||
pass | ||
|
||
#line 247 | ||
def positional_only_arg(a, /): | ||
pass | ||
|
||
#line 145 | ||
#line 251 | ||
def all_markers(a, b, /, c, d, *, e, f): | ||
pass | ||
|
||
# line 149 | ||
# line 255 | ||
def all_markers_with_args_and_kwargs(a, b, /, c, d, *args, e, f, **kwargs): | ||
pass | ||
|
||
#line 153 | ||
#line 259 | ||
def all_markers_with_defaults(a, b=1, /, c=2, d=3, *, e=4, f=5): | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:meth:`inspect.getsource` now returns correct source code for inner class | ||
with same name as module level class. Decorators are also returned as part | ||
of source of the class. Patch by Karthikeyan Singaravelan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be
cls218
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This to check that the inner class which has the same name
cls213
insidefunc212
doesn't conflict with this classcls213
. Previously regex was used and hence there were cases where two classes with same name defined under different scopes might conflict with each other returning wrong results.