Return source location (path, lineno) for the given object. If the source cannot be determined return ("", -1). The line number is 0-based.
(obj: object)
| 1540 | |
| 1541 | |
| 1542 | def getfslineno(obj: object) -> tuple[str | Path, int]: |
| 1543 | """Return source location (path, lineno) for the given object. |
| 1544 | |
| 1545 | If the source cannot be determined return ("", -1). |
| 1546 | |
| 1547 | The line number is 0-based. |
| 1548 | """ |
| 1549 | # xxx let decorators etc specify a sane ordering |
| 1550 | # NOTE: this used to be done in _pytest.compat.getfslineno, initially added |
| 1551 | # in 6ec13a2b9. It ("place_as") appears to be something very custom. |
| 1552 | obj = get_real_func(obj) |
| 1553 | if hasattr(obj, "place_as"): |
| 1554 | obj = obj.place_as |
| 1555 | |
| 1556 | try: |
| 1557 | code = Code.from_function(obj) |
| 1558 | except TypeError: |
| 1559 | try: |
| 1560 | fn = inspect.getsourcefile(obj) or inspect.getfile(obj) # type: ignore[arg-type] |
| 1561 | except TypeError: |
| 1562 | return "", -1 |
| 1563 | |
| 1564 | fspath = (fn and absolutepath(fn)) or "" |
| 1565 | lineno = -1 |
| 1566 | if fspath: |
| 1567 | try: |
| 1568 | _, lineno = findsource(obj) |
| 1569 | except OSError: |
| 1570 | pass |
| 1571 | return fspath, lineno |
| 1572 | |
| 1573 | return code.path, code.firstlineno |
| 1574 | |
| 1575 | |
| 1576 | def _byte_offset_to_character_offset(str, offset): |