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

Ignore fields with leading "_" #77

Closed
skewty opened this issue Oct 9, 2019 · 3 comments
Closed

Ignore fields with leading "_" #77

skewty opened this issue Oct 9, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@skewty
Copy link

skewty commented Oct 9, 2019

import xmltodict, typing
from pydantic import BaseModel

Model = typing.TypeVar('Model', bound='HIPEventBase')

class HIPEventBase(BaseModel):
    __ROOT_TAG__ = "FOO"

    @classmethod
    def get_root_tag(cls) -> str:
        return cls.__ROOT_TAG__

    def xml(self) -> str:
        return xmltodict.unparse({self.__class__.get_root_tag(): self.dict(by_alias=True)})

    @classmethod
    def parse_xml(cls: typing.Type[Model], b: str) -> Model:
        # noinspection PyArgumentList
        return cls(**xmltodict.parse(b)[cls.get_root_tag()])

    x: int
    y: int

Please don't show __ROOT_TAG__ as a field that needs to be populated in constructor.

I think it would also be expected that any field starting with '_' is ignored (perhaps check into implementation details in pydantic source). I have verified that a leading __ prevents pydantic from creating a "field".

@koxudaxi koxudaxi added the enhancement New feature or request label Oct 10, 2019
@koxudaxi
Copy link
Owner

Sorry, I don't know the behavior.
I can ignore the filed easy.
I will create the PR.
Thank you.

@skewty
Copy link
Author

skewty commented Oct 11, 2019

It's merged so I will close this :)

@skewty skewty closed this as completed Oct 11, 2019
@koxudaxi
Copy link
Owner

We should wait to approved for two business days

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

No branches or pull requests

2 participants