Skip to content

Commit 5c87f5b

Browse files
committed
Fixed relative path calculation for unresolvable cases.
1 parent ebc725c commit 5c87f5b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

taskiq_dependencies/graph.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,10 @@ def _build_graph(self) -> None: # noqa: C901
177177
hints = get_type_hints(origin.__init__)
178178
except NameError:
179179
_, src_lineno = inspect.getsourcelines(origin)
180-
src_file = Path(inspect.getfile(origin)).relative_to(
181-
Path.cwd(),
182-
)
180+
src_file = Path(inspect.getfile(origin))
181+
cwd = Path.cwd()
182+
if src_file.is_relative_to(cwd):
183+
src_file = src_file.relative_to(cwd)
183184
warnings.warn(
184185
"Cannot resolve type hints for "
185186
f"a class {origin.__name__} defined "
@@ -198,9 +199,10 @@ def _build_graph(self) -> None: # noqa: C901
198199
hints = get_type_hints(dep.dependency)
199200
except NameError:
200201
_, src_lineno = inspect.getsourcelines(dep.dependency) # type: ignore
201-
src_file = Path(inspect.getfile(dep.dependency)).relative_to(
202-
Path.cwd(),
203-
)
202+
src_file = Path(inspect.getfile(dep.dependency))
203+
cwd = Path.cwd()
204+
if src_file.is_relative_to(cwd):
205+
src_file = src_file.relative_to(cwd)
204206
warnings.warn(
205207
"Cannot resolve type hints for "
206208
f"a function {dep.dependency.__name__} defined "
@@ -217,11 +219,10 @@ def _build_graph(self) -> None: # noqa: C901
217219
)
218220
except NameError:
219221
_, src_lineno = inspect.getsourcelines(dep.dependency.__class__)
220-
src_file = Path(
221-
inspect.getfile(dep.dependency.__class__),
222-
).relative_to(
223-
Path.cwd(),
224-
)
222+
src_file = Path(inspect.getfile(dep.dependency.__class__))
223+
cwd = Path.cwd()
224+
if src_file.is_relative_to(cwd):
225+
src_file = src_file.relative_to(cwd)
225226
cls_name = dep.dependency.__class__.__name__
226227
warnings.warn(
227228
"Cannot resolve type hints for "

0 commit comments

Comments
 (0)