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

populate - arg throw_on_unknown_keyword #125

Open
user706 opened this issue Jul 2, 2018 · 0 comments
Open

populate - arg throw_on_unknown_keyword #125

user706 opened this issue Jul 2, 2018 · 0 comments

Comments

@user706
Copy link

user706 commented Jul 2, 2018

Hi,

I would like the __init__ and populate methods ref, to have the following signature:

def __init__(self,  throw_on_unknown_keyword = False, **kwargs):
    # ...

def populate(self, throw_on_unknown_keyword = False, **values):
    # ...
            if structure_name in values:
                field.__set__(self, values.pop(structure_name))
            elif throw_on_unknown_keyword and structure_name != 'throw_on_unknown_keyword' :
                throw # ...
        for name, _, field in fields:
            if name in values:
                field.__set__(self, values.pop(name))
            elif throw_on_unknown_keyword and name != 'throw_on_unknown_keyword':
                throw # ...

# warning: I have not checked the details!

Reason: I wrap the Model inside a class:

class A:
        class ModelA(models.Base):
        a = fields.DateTimeField(required=True)
        b = fields.FloatField(required=True)
        c = fields.FloatField(required=True)

    def __init__(self, **kwargs):
        self.model = self.ModelA(throw_on_unknown_keyword = True, **kwargs)

    # #Instead of
    #def __init__(self, a, b, c):
    #   self.model = self.ModelA(a = a, b = b, c = c)

With throw_on_unknown_keyword = True, I keep the constructor of A and the model synchronized, and get an exception if they are not synchronized.

Is that feasible?

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

No branches or pull requests

1 participant