MCPcopy
hub / github.com/pytest-dev/pytest / __init__

Method __init__

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

Source from the content-addressed store, hash-verified

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