What if we implement something like this:
>>> import json
>>> from mimesis.cards import PersonCard
>>> json.dumps(next(p), ident=4)
{
"first_name": "Julio",
"last_name": "Santos",
"email": "[email protected]",
"age": 33,
"child_count": 3,
"gender": "male",
"work_experience": 11
...
}
Or upgrade schema provider to return non contradictory data. What do you think about this?
I think that it's partially duplicate schema.Field.
:thinking: It's better to add good documentation about schema.Field to docs I think. Structured data is too specific case which better to solve using custom schema (schema.Field, schema.Schema).
@lk-geimfari Schema field can return contradict data. For example female first name and male last name.
@duckyou But you can use **kwargs for it.
_ = Field('ru')
name = _('name', gender=Gender.FEMALE)
surname = _('surname', gender=Gender.FEMALE)
@lk-geimfari But if i want random gender?
Ok... Some time ago there was a proposal to implement feature which is allow use enums with random.choice function.
Something like this:
class MimesisEnumMeta(EnumMeta):
"""Updated metaclass with index support."""
def __getitem__(self, key):
"""Return enum item if it exist.
:param key: index or name
:return: enum item
"""
if isinstance(key, int):
key = self._member_names_[key]
return self._member_map_[key]
class EnumMixin(metaclass=MimesisEnumMeta):
"""Enum mixin with updated metaclass."""
pass
class Gender(EnumMixin, Enum):
"""Represents genders.
Value for a lot of methods which
takes argument ``gender``.
"""
FEMALE = 'female'
MALE = 'male'
We can use like:
_ = Field('ru')
gender_enum = random.choice(Gender)
name = _('name', gender=gender_enum)
surname = _('surname', gender=gender_enum)
There is no need to implement it in a core. A user can do it manually:
random_gender = lambda: random.choice(list(Gender))
name = _('name', gender=random_gender())
@lk-geimfari You goddamn right :bangbang:
Also last questions: what about build-in schemas? Implement some schemas or omit it?
@duckyou I think that we should implement it as a third-party package, for example, named mimesis-schemas. I think that this is a compromise between the simplicity of the core and its capabilities.
from mimesis_schema import SomeCard
# ...
# ....
In core package, we need to improve existing features and fix bugs. It's our priority.
@lk-geimfari you are reading my mind :wink: :+1:
Can you plz create mimesis_schema repo?
@duckyou You can do it by yourself too. You're a member of mimesis-lab
Anyway, i have created repo for you: https://github.com/mimesis-lab/mimesis_schema
Nice! Closing.
Most helpful comment
@duckyou You can do it by yourself too. You're a member of
mimesis-labAnyway, i have created repo for you: https://github.com/mimesis-lab/mimesis_schema