-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
Add support for native enum docstring #3668
Conversation
Reviewer's Guide by SourceryThis pull request adds support for native enum docstrings in Strawberry. The implementation focuses on using the No diagrams generated as the changes look simple and do not need a visual representation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
@@ -0,0 +1,24 @@ | |||
Release type: patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jirikuncar - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider updating the project documentation to mention this new feature of using native enum docstrings as descriptions in the schema. This will help users discover and utilize this enhancement.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟡 Documentation: 1 issue found
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
evaled_type, description=evaled_type.__doc__ | ||
)._enum_definition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider handling cases where doc might be None
The current implementation assumes that evaled_type.doc always exists. Consider using a default value or a conditional to handle cases where the docstring might be None, e.g., description=evaled_type.__doc__ or ''
.
evaled_type, description=evaled_type.__doc__ | |
)._enum_definition | |
evaled_type, | |
description=evaled_type.__doc__ if evaled_type.__doc__ is not None else '' | |
)._enum_definition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description
can be None
🤔
Thanks for adding the Here's a preview of the changelog: Use native enum This change improves consistency between Python enums and schema representations, # somewhere.py
from enum import Enum
class AnimalKind(Enum):
"""The kind of animal."""
AXOLOTL, CAPYBARA = range(2) This will generate the following schema: """The kind of animal."""
enum AnimalKind {
AXOLOTL
CAPYBARA
} Here's the tweet text:
|
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
There's been previous discussion about using docstrings to generate descriptions (see #653). The general consensus has been that people are worried about unintentionally leaking internal comments because they weren't expecting this behaviour. That being said, with the native enums, we don't have the If we are adding this feature, I think it would also be good to allow docstrings to set the descriptions for the enum values as well (we currently have class Foo(Enum):
"""This is a Foo enum."""
BAR = "bar"
"""This is bar"""
BAZ = "baz"
"""This is baz""" |
|
I think this should be configurable at schema level. so when we pass stuff to graphql-core we use this condition and iterate over all the types, if there is no doc we take the doc from the origin class. |
Apologies
I wasn't thorough in my research before creating this PR. I wanted to simplify the codebase by removing many enum decorators and moving the description to docstrings where I would expect it. As I appreciate maintainers time, I would understand if this PR gets closed without any comment. If you find this PR useful please continue in the discussion #653.
Description
Adds support for native enum
__doc__
.Types of Changes
Issues Fixed or Closed by This PR
partially addresses Implicit description from class docstring #653 for Enums only
Support generating GraphQL descriptions from docstrings #1645
Checklist
Summary by Sourcery
Introduce support for using native enum docstrings as descriptions in schema enum types, enhance the enum creation process to incorporate these docstrings, and add corresponding tests and documentation.
New Features:
__doc__
as the description for schema enum types.Enhancements:
create_enum
function to utilize the native enum__doc__
for descriptions.Documentation:
RELEASE.md
file documenting the use of native enum__doc__
for schema descriptions.Tests:
__doc__
is correctly used as the description in the schema.