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

sphinx/ext/autodoc/__init__.py:719 could lead to __bool__ method call, what can lead to side effect or direct failure in case it generate an error #8522

Closed
ArtyomKaltovich opened this issue Dec 7, 2020 · 2 comments · Fixed by #8523

Comments

@ArtyomKaltovich
Copy link
Contributor

Describe the bug
The code is the following:

    keep = False
    if safe_getattr(member, '__sphinx_mock__', None) is not None:
        # mocked module or object
        pass

But if safe_getattr returns some object with redefined __bool__, e.g.

 def __bool__(self):
       raise TypeError("Do not pass this object to if and while clause, use all or any function")

 def __bool__(self):
       write_to_db()
       send_email()
       request_http()
       log()
       some_other_side_effect

This code will be executed and will lead to sphinx failure or unexpected side effects.

To Reproduce
Unfortunately I can't reproduce it as a toy example, but it lead to failure on my work project.

Expected behavior
Do not call user code.

@tk0miya
Copy link
Member

tk0miya commented Dec 8, 2020

+0; autodoc analyzes the target code by dynamic inspection. So we can't promise it will never call a method having side effects (like __bool__). I can accept the fix. But it does not mean "autodoc will never call __bool__ and other methods on analysis.

@ArtyomKaltovich
Copy link
Contributor Author

ArtyomKaltovich commented Dec 8, 2020

Hello again)

I fix the changelog in PR. I understand there can be another side effects or user code calls, and I've just remove this one. :)

The issue was created just to submit this exact case.

tk0miya added a commit that referenced this issue Dec 12, 2020
fix #8522: sphinx could lead to `__bool__` method call, what can lead to side effect or direct failure in case it generate an error bug
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.