Skip to content
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

infinite recursion in GriffeLoader.expand_wildcards #57

Closed
analog-cbarber opened this issue Mar 6, 2022 · 4 comments
Closed

infinite recursion in GriffeLoader.expand_wildcards #57

analog-cbarber opened this issue Mar 6, 2022 · 4 comments
Labels
bug Something isn't working griffe: wildcard-imports Related to wildcard imports

Comments

@analog-cbarber
Copy link

I was using mkdocstrings 0.18 to build api documentation, and got a recursion error:

File "/Users/cbarber/miniconda3/envs/cavr-dev/lib/python3.8/site-packages/griffe/loader.py", line 204, in expand_wildcards
    self.expand_wildcards(self.modules_collection[member.target_path])  # type: ignore[union-attr]
  File "/Users/cbarber/miniconda3/envs/cavr-dev/lib/python3.8/site-packages/griffe/loader.py", line 208, in expand_wildcards
    self.expand_wildcards(member, seen)  # type: ignore[arg-type]
  File "/Users/cbarber/miniconda3/envs/cavr-dev/lib/python3.8/site-packages/griffe/loader.py", line 207, in expand_wildcards
    elif not member.is_alias and member.is_module and member.path not in seen:
  File "/Users/cbarber/miniconda3/envs/cavr-dev/lib/python3.8/site-packages/griffe/dataclasses.py", line 402, in is_module
    return self.kind is Kind.MODULE  # noqa: DAR201
RecursionError: maximum recursion depth exceeded while calling a Python object

Look at the code, it appears that there is a case where expand_wildcards calls itself recursively without passing
the seen set:

self.expand_wildcards(self.modules_collection[member.target_path]) # type: ignore[union-attr]

When I add, seen to the call, the failure becomes:

I instead get this:

  File "/Users/cbarber/miniconda3/envs/cavr-dev/lib/python3.8/site-packages/griffe/dataclasses.py", line 856, in parent
    self._target.aliases[self.path] = self  # type: ignore[union-attr]  # we just checked the target is not None
  File "/Users/cbarber/miniconda3/envs/cavr-dev/lib/python3.8/site-packages/griffe/dataclasses.py", line 791, in __getattr__
    raise CyclicAliasError([self.target_path] + error.chain)
griffe.exceptions.CyclicAliasError: Cyclic aliases detected:
  antlr4.atn.Transition.Transition
  antlr4.atn.ATNState.Transition
  antlr4.atn.Transition.Transition

I don't know if this second issue is a Griffe error or an error in mkdocstrings for not catching it.

I don't know how to tell Griffe not to bother looking at that package.

@pawamoy
Copy link
Member

pawamoy commented Mar 6, 2022

Hi @analog-cbarber, thanks for the report. Do you have a public repo I can use to replicate the issue?

@analog-cbarber
Copy link
Author

Sorry, I am afraid this is internal code. I can tell you that this was using a conda environment
with version 4.9.3 of antlr-python-runtime:

$ conda list antlr
# packages in environment at /Users/cbarber/miniconda3/envs/cavr-dev:
#
# Name                    Version                   Build  Channel
antlr-python-runtime      4.9.3              pyhd8ed1ab_1    conda-forge

@pawamoy
Copy link
Member

pawamoy commented Mar 7, 2022

I see, I'll simply apply the fix you suggest then! Thanks again!

@pawamoy
Copy link
Member

pawamoy commented Apr 4, 2022

That should be fixed now. Don't hesitate to open new issues if the exception still gets triggered (I expect it will).

@pawamoy pawamoy closed this as completed Apr 4, 2022
@pawamoy pawamoy added bug Something isn't working griffe: wildcard-imports Related to wildcard imports labels Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working griffe: wildcard-imports Related to wildcard imports
Projects
None yet
Development

No branches or pull requests

2 participants