Skip to content

Make components dicts public attributes of Components class#634

Merged
lafrech merged 1 commit intodevfrom
components_public_attributes
Feb 6, 2021
Merged

Make components dicts public attributes of Components class#634
lafrech merged 1 commit intodevfrom
components_public_attributes

Conversation

@lafrech
Copy link
Copy Markdown
Member

@lafrech lafrech commented Feb 5, 2021

This allows the caller to check a component is already registered. For instance to avoid registering it several times.

I could try/except but I think exceptions are more suited for... exceptions. If testing is the normal flow (because the code is expected to run several time and only register once) I think the try/except method does not express the intent.

Another reason is that even in apispec itself, _schemas is accessed from another class.

flask-smorest auto registers default responses when a response contains a name from http.HTTPStatus. I'd like to allow the user to register his own response and only register a default response if he didn't. There my code needs to register the response only if it is not in components.schemas and it is a pity to keep track of which is registered in another list. More on this in marshmallow-code/flask-smorest#208. This use case is not that important. I just don't see why those should be private.

@lafrech lafrech requested a review from Bangertm February 5, 2021 21:37
Copy link
Copy Markdown
Collaborator

@Bangertm Bangertm left a comment

Choose a reason for hiding this comment

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

Looks good to me. No issue making these public that I can see.

@lafrech lafrech merged commit 6fcee8e into dev Feb 6, 2021
@lafrech lafrech deleted the components_public_attributes branch February 6, 2021 18:19
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