File tree Expand file tree Collapse file tree 2 files changed +5
-11
lines changed Expand file tree Collapse file tree 2 files changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ def __init__(self, obj: object = None) -> None:
30
30
elif isinstance (obj , str ):
31
31
self .lines = deindent (obj .split ("\n " ))
32
32
else :
33
- self .lines = deindent (getsource (obj ).lines )
33
+ rawcode = getrawcode (obj )
34
+ src = inspect .getsource (rawcode )
35
+ self .lines = deindent (src .split ("\n " ))
34
36
35
37
def __eq__ (self , other : object ) -> bool :
36
38
if not isinstance (other , Source ):
@@ -141,12 +143,6 @@ def getrawcode(obj, trycall: bool = True):
141
143
return obj
142
144
143
145
144
- def getsource (obj ) -> Source :
145
- obj = getrawcode (obj )
146
- strsrc = inspect .getsource (obj )
147
- return Source (strsrc )
148
-
149
-
150
146
def deindent (lines : Iterable [str ]) -> List [str ]:
151
147
return textwrap .dedent ("\n " .join (lines )).splitlines ()
152
148
Original file line number Diff line number Diff line change @@ -307,12 +307,10 @@ def x():
307
307
pass
308
308
309
309
310
- def test_getsource_fallback () -> None :
311
- from _pytest ._code .source import getsource
312
-
310
+ def test_source_fallback () -> None :
311
+ src = Source (x )
313
312
expected = """def x():
314
313
pass"""
315
- src = getsource (x )
316
314
assert str (src ) == expected
317
315
318
316
You can’t perform that action at this time.
0 commit comments