Skip to content

Commit

Permalink
Fixed relative path calculation for unresolvable cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Dec 9, 2024
1 parent ebc725c commit 5c87f5b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions taskiq_dependencies/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ def _build_graph(self) -> None: # noqa: C901
hints = get_type_hints(origin.__init__)
except NameError:
_, src_lineno = inspect.getsourcelines(origin)
src_file = Path(inspect.getfile(origin)).relative_to(
Path.cwd(),
)
src_file = Path(inspect.getfile(origin))
cwd = Path.cwd()
if src_file.is_relative_to(cwd):
src_file = src_file.relative_to(cwd)
warnings.warn(
"Cannot resolve type hints for "
f"a class {origin.__name__} defined "
Expand All @@ -198,9 +199,10 @@ def _build_graph(self) -> None: # noqa: C901
hints = get_type_hints(dep.dependency)
except NameError:
_, src_lineno = inspect.getsourcelines(dep.dependency) # type: ignore
src_file = Path(inspect.getfile(dep.dependency)).relative_to(
Path.cwd(),
)
src_file = Path(inspect.getfile(dep.dependency))
cwd = Path.cwd()
if src_file.is_relative_to(cwd):
src_file = src_file.relative_to(cwd)
warnings.warn(
"Cannot resolve type hints for "
f"a function {dep.dependency.__name__} defined "
Expand All @@ -217,11 +219,10 @@ def _build_graph(self) -> None: # noqa: C901
)
except NameError:
_, src_lineno = inspect.getsourcelines(dep.dependency.__class__)
src_file = Path(
inspect.getfile(dep.dependency.__class__),
).relative_to(
Path.cwd(),
)
src_file = Path(inspect.getfile(dep.dependency.__class__))
cwd = Path.cwd()
if src_file.is_relative_to(cwd):
src_file = src_file.relative_to(cwd)
cls_name = dep.dependency.__class__.__name__
warnings.warn(
"Cannot resolve type hints for "
Expand Down

0 comments on commit 5c87f5b

Please sign in to comment.