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

3.3.0+ Crashes when assigning __init__ rather than defining it #488

Open
Daverball opened this issue Oct 3, 2024 · 0 comments
Open

3.3.0+ Crashes when assigning __init__ rather than defining it #488

Daverball opened this issue Oct 3, 2024 · 0 comments

Comments

@Daverball
Copy link

If you do something like the following:

class Base:
    def __init__(self) -> None:
        pass


class SomeMixin:
    if TYPE_CHECKING:
        # forward declare __init__
        __init__ = Base.__init__  # type:ignore[assignment]

Autoapi will crash in the mapping step when trying to access overloads on the class node, this is presumably because the following check does not guard against non-method nodes:

if self.constructor:
overload_data = self.constructor.obj["overloads"]
autodoc_typehints = getattr(
self.app.config, "autodoc_typehints", "signature"
)
show_annotations = autodoc_typehints not in ("none", "description")
overloads = [
(
_format_args(args, show_annotations, ignore_self="self"),
return_annotation,
)
for args, return_annotation in overload_data
]

I couldn't really figure out why this didn't cause a crash prior to 3.3.0, but at the very least it should be fairly simple to avoid a crash here, by adding an additional guard. Doing something more sophisticated would require more work. But I don't think it is necessary, considering this is a really rare hacky workaround and in fact I no longer needed to use it in the places that caused the crash.

But it still can't hurt to avoid this crash in the future, since it was a pain to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant