Skip to content

Instantly share code, notes, and snippets.

@lsmith77
Last active August 30, 2021 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsmith77/c916b7b4adf3b61a3a3c15ea30aef3a2 to your computer and use it in GitHub Desktop.
Save lsmith77/c916b7b4adf3b61a3a3c15ea30aef3a2 to your computer and use it in GitHub Desktop.
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")
ValueError: "EntityOut" object has no field "_lang"
@lsmith77
Copy link
Author

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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment