Last active
August 30, 2021 13:16
-
-
Save lsmith77/c916b7b4adf3b61a3a3c15ea30aef3a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydantic import BaseModel | |
class EntityOut(BaseModel): | |
category: str | |
text: str | |
label: str | |
class Config: | |
underscore_attrs_are_private = True | |
def __init__(self, _lang, text, category): | |
self._lang = lang | |
self.text = text | |
self.category = category | |
@property | |
def get_label(self): | |
return self._lang.trans("rules." + self.category + "_label") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ValueError: "EntityOut" object has no field "_lang" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If I make the field explicit, then I run into all sorts of validation issues, which I don't get either. I just want pydantic to not bother at all looking at _lang ...