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

no decimal.Decimal type support #170

Closed
joeblackwaslike opened this Issue May 3, 2018 · 3 comments

Comments

3 participants
@joeblackwaslike

joeblackwaslike commented May 3, 2018

Please let me know if I'm doing something incorrect here, and if not, I would love to submit a pull request fixing this issue :)

from decimal import Decimal
from pydantic import BaseModel

class Test(BaseModel):
    value: Decimal = None
---------------------------------------------------------------------------
ConfigError                               Traceback (most recent call last)
<ipython-input-12-7f02e90f9299> in <module>()
----> 1 class Test(BaseModel):
      2     value: Decimal = None
      3

/usr/local/Cellar/python/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pydantic/main.py in __new__(mcs, name, bases, namespace)
    116                     annotation=annotations.get(var_name),
    117                     class_validators=vg.get_validators(var_name),
--> 118                     config=config,
    119                 )
    120

/usr/local/Cellar/python/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pydantic/fields.py in infer(cls, name, value, annotation, class_validators, config)
     82             required=required,
     83             model_config=config,
---> 84             description=field_config and field_config.get('description'),
     85         )
     86

/usr/local/Cellar/python/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pydantic/fields.py in __init__(self, name, type_, class_validators, default, required, model_config, alias, allow_none, description)
     68         self.shape: Shape = Shape.SINGLETON
     69         self.info = {}
---> 70         self.prepare()
     71
     72     @classmethod

/usr/local/Cellar/python/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pydantic/fields.py in prepare(self)
    111
    112         self._populate_sub_fields()
--> 113         self._populate_validators()
    114
    115         self.info = {

/usr/local/Cellar/python/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pydantic/fields.py in _populate_validators(self)
    190             v_funcs = (
    191                 *tuple(v.func for v in self.class_validators if not v.whole and v.pre),
--> 192                 *(get_validators() if get_validators else find_validators(self.type_)),
    193                 *tuple(v.func for v in self.class_validators if not v.whole and not v.pre),
    194             )

/usr/local/Cellar/python/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pydantic/validators.py in find_validators(type_)
    162         except TypeError as e:
    163             raise TypeError(f'error checking inheritance of {type_!r} (type: {display_as_type(type_)})') from e
--> 164     raise ConfigError(f'no validator found for {type_}')

ConfigError: no validator found for <class 'decimal.Decimal'>

BTW, excellent project here, it's one of my new favorites!

@samuelcolvin

This comment has been minimized.

Owner

samuelcolvin commented May 3, 2018

no decimal support, it needs to be added, it's mentioned in #161 too.

PR welcome.

@Gr1N

This comment has been minimized.

Collaborator

Gr1N commented May 3, 2018

I will going to implement decimal support in a few days, just wait a little :)

Gr1N added a commit to Gr1N/pydantic that referenced this issue May 6, 2018

Gr1N added a commit to Gr1N/pydantic that referenced this issue May 6, 2018

samuelcolvin added a commit that referenced this issue May 10, 2018

@Gr1N

This comment has been minimized.

Collaborator

Gr1N commented May 10, 2018

@joeblackwaslike decimal support added in #175.
@samuelcolvin looks like this issue can be closed.

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