@@ -177,9 +177,10 @@ def _build_graph(self) -> None: # noqa: C901
177
177
hints = get_type_hints (origin .__init__ )
178
178
except NameError :
179
179
_ , 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 )
183
184
warnings .warn (
184
185
"Cannot resolve type hints for "
185
186
f"a class { origin .__name__ } defined "
@@ -198,9 +199,10 @@ def _build_graph(self) -> None: # noqa: C901
198
199
hints = get_type_hints (dep .dependency )
199
200
except NameError :
200
201
_ , 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 )
204
206
warnings .warn (
205
207
"Cannot resolve type hints for "
206
208
f"a function { dep .dependency .__name__ } defined "
@@ -217,11 +219,10 @@ def _build_graph(self) -> None: # noqa: C901
217
219
)
218
220
except NameError :
219
221
_ , 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 )
225
226
cls_name = dep .dependency .__class__ .__name__
226
227
warnings .warn (
227
228
"Cannot resolve type hints for "
0 commit comments