MCPcopy Create free account
hub / github.com/pytest-dev/pytest / __init__

Method __init__

src/_pytest/_code/source.py:23–38  ·  view source on GitHub ↗
(self, obj: object = None)

Source from the content-addressed store, hash-verified

21 """
22
23 def __init__(self, obj: object = None) -> None:
24 if not obj:
25 self.lines: List[str] = []
26 elif isinstance(obj, Source):
27 self.lines = obj.lines
28 elif isinstance(obj, (tuple, list)):
29 self.lines = deindent(x.rstrip("\n") for x in obj)
30 elif isinstance(obj, str):
31 self.lines = deindent(obj.split("\n"))
32 else:
33 try:
34 rawcode = getrawcode(obj)
35 src = inspect.getsource(rawcode)
36 except TypeError:
37 src = inspect.getsource(obj) # type: ignore[arg-type]
38 self.lines = deindent(src.split("\n"))
39
40 def __eq__(self, other: object) -> bool:
41 if not isinstance(other, Source):

Callers

nothing calls this directly

Calls 3

deindentFunction · 0.85
getrawcodeFunction · 0.85
getsourceMethod · 0.80

Tested by

no test coverage detected