From 1408184c57c44888eec0f12be45973395ce09a8b Mon Sep 17 00:00:00 2001 From: botbikamordehai2-sketch Date: Thu, 28 May 2026 21:12:50 +0300 Subject: [PATCH 1/2] fix: prevent infinite recursion when evaluating TYPE_CHECKING sections (closes #868) --- pdoc/doc_types.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pdoc/doc_types.py b/pdoc/doc_types.py index d2dd5323..d0580701 100644 --- a/pdoc/doc_types.py +++ b/pdoc/doc_types.py @@ -114,12 +114,21 @@ def safe_eval_type( # Simple _eval_type has failed. We now execute all TYPE_CHECKING sections in the module and try again. if module: assert module.__dict__ is globalns + # Guard against re-entering this block for the same module (prevents infinite recursion) + if getattr(module, '_pdoc_evaluating_type_checking', False): + warnings.warn( + f"Circular dependency detected while resolving type annotation {t} for {fullname} in module {module.__name__}. Returning unevaluated." + ) + return t + module._pdoc_evaluating_type_checking = True try: _eval_type_checking_sections(module, set()) except Exception as e: warnings.warn( f"Failed to run TYPE_CHECKING code while parsing {t} type annotation for {fullname}: {e}" ) + finally: + del module._pdoc_evaluating_type_checking try: return _eval_type(t, globalns, None) except (AttributeError, NameError): From 5bae02487709edcdcd63a0c224f2aaa65c02f9c3 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 28 May 2026 18:13:35 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- pdoc/doc_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdoc/doc_types.py b/pdoc/doc_types.py index d0580701..4d2c2955 100644 --- a/pdoc/doc_types.py +++ b/pdoc/doc_types.py @@ -115,7 +115,7 @@ def safe_eval_type( if module: assert module.__dict__ is globalns # Guard against re-entering this block for the same module (prevents infinite recursion) - if getattr(module, '_pdoc_evaluating_type_checking', False): + if getattr(module, "_pdoc_evaluating_type_checking", False): warnings.warn( f"Circular dependency detected while resolving type annotation {t} for {fullname} in module {module.__name__}. Returning unevaluated." )