New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolving multiple imports guarded by typing.TYPE_CHECKING #375
Comments
Your proposition sounds ok, PR welcome 🤗 |
Could be at least I get the same 'WARNING: Failed guarded type import with ImportError("cannot import name 'AbstractSetIntStr'' that you mentioned |
@hojo0590 yes, looking at the lines you've pasted, it looks like the same problem. |
Pydantic v2 uses TYPE_CHECKING more aggressively in ways that sphinx-autodoc-typehints currently doesn't cope with correctly. See tox-dev/sphinx-autodoc-typehints#375.
Pydantic v2 uses TYPE_CHECKING more aggressively in ways that sphinx-autodoc-typehints currently doesn't cope with correctly. See tox-dev/sphinx-autodoc-typehints#375.
@hojo0590 did you find solution to resolve this problem "cannot import name 'AbstractSetIntStr' from 'pydantic._internal._utils'" ? |
I have implemented a draft that should fix this issue: #393 @lchojnacki Could you please test if that fix works for your Bokeh use case? However, the fix does not work for Pydantic because Pydantic uses |
@hojo0590 Running the following with Python 3.12 from typing import Any
AnyClassMethod = classmethod[Any, Any, Any] yields
I couldn't really find any information on whether code in |
Just hopped 😳hence why if it fails is silent error. |
@Mr-Pepe sorry, I did not make it clear, that I haven't tried (Python 3.12) myself yet - thanks for trying it, I learned something |
Hello!
At the beginning: I saw #22, but this case looks like a separate issue.
Description
Version 1.15.0 introduced a change in the way imports guarded by
if typing.TYPE_CHECKING
are handled. The_resolve_type_guarded_imports
function searches forTYPE_CHECKING
occurrences using a regular expression, and then runs the code inside that block withexec
.This solution is pretty smart and it works, until we have multiple levels of
TYPE_CHECKING
guards.Example
bokeh/model/model.py
: https://github.com/bokeh/bokeh/blob/branch-3.3/src/bokeh/model/model.py#L42bokeh/core/has_props.py
: https://github.com/bokeh/bokeh/blob/branch-3.3/src/bokeh/core/has_props.py#L98The resolver finds
TYPE_CHECKING
guard inmodel.py
and tries to execute the import, but it's unable to find theSetter
inhas_props.py
(theTYPE_CHECKING
flag is set toFalse
, and the filehas_props.py
is just being executed by python, not parsed by_resolve_type_guarded_imports
function).Proposition
I'm wondering if it would be possible to resolve this type of imports recursively, using
_resolve_type_guarded_imports
? Or do you have any other ideas? I guess I have to stay with version <1.15.0 until this gets fixed.The text was updated successfully, but these errors were encountered: