Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08738ce

Browse files
[3.14]gh-139783: Fix inspect.getsourcelines() for the case when a decorator is followed by a comment or an empty line (GH-139836) (GH-139889)
(cherry picked from commitf4104f5)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent5d34830 commit08738ce

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

‎Lib/inspect.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,9 @@ def __init__(self):
10651065

10661066
deftokeneater(self,type,token,srowcol,erowcol,line):
10671067
ifnotself.startedandnotself.indecorator:
1068-
iftype==tokenize.INDENTortoken=="async":
1068+
iftypein (tokenize.INDENT,tokenize.COMMENT,tokenize.NL):
1069+
pass
1070+
eliftoken=="async":
10691071
pass
10701072
# skip any decorators
10711073
eliftoken=="@":

‎Lib/test/test_inspect/inspect_fodder2.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,16 @@ def func383():
388388
)
389389
returnge385
390390

391+
# line 391
392+
@decorator
393+
# comment
394+
deffunc394():
395+
return395
396+
397+
# line 397
398+
@decorator
399+
400+
deffunc400():
401+
return401
402+
391403
pass# end of file

‎Lib/test/test_inspect/test_inspect.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,10 @@ def test_generator_expression(self):
12231223
self.assertSourceEqual(next(mod2.ge377),377,380)
12241224
self.assertSourceEqual(next(mod2.func383()),385,388)
12251225

1226+
deftest_comment_or_empty_line_after_decorator(self):
1227+
self.assertSourceEqual(mod2.func394,392,395)
1228+
self.assertSourceEqual(mod2.func400,398,401)
1229+
12261230

12271231
classTestNoEOL(GetSourceBase):
12281232
defsetUp(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix:func:`inspect.getsourcelines` for the case when a decorator is followed
2+
by a comment or an empty line.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp