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

fix: Prevent crash in case of empty dataclasses #56

Merged
merged 2 commits into from
Jun 28, 2020

Conversation

jaredkhan
Copy link
Contributor

Ran into this when applying mkdocstrings to a real life project. I won't pretend that there was a legitimate reason to use an empty dataclass in my code, but thought it was worth preventing the crash 🙈

Comment on lines 410 to 411
if "__annotations__" in all_members:
for field_name, annotation in all_members["__annotations__"].items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, why don't we iterate on __dataclass_fields__ since we already asserted its existence? Besides, the dataclass field also contains a default value, which we could use for #50

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a better idea! Updated.

As far as I can tell, actually using the default value would be a bit more work since it would have to be added to the Attribute object and then presumably used in some serialisation somewhere but I can't immediately see where. So I guess that can happen separately :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right 🙂 I will merge this PR as it is, thanks!

@pawamoy
Copy link
Member

pawamoy commented Jun 28, 2020

Thanks again for your contributions, this is really appreciated 🙂

I won't pretend that there was a legitimate reason to use an empty dataclass in my code, but thought it was worth preventing the crash

Haha yeah, I agree we should prevent a crash anyway!

I left just one comment!

@pawamoy pawamoy merged commit 835c066 into mkdocstrings:master Jun 28, 2020
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

Successfully merging this pull request may close these issues.

2 participants