> > > Any time I am using a function from a library that accepts keyword > > arguments. For example, an ORM model constructor that accepts fields as > > keyword arguments (like Django). > > That's not the same issue at all, if I'm understanding you correctly. > In any case, surely you need to do some validation on your dictionary of > keyword arguments? Otherwise you are setting yourself up for a world of > pain. If you do that, you should take the opportunity to decide what to > do with invalid keys. >
The specific pain point that motivated this was constructing many interrelated models using a dict. So, for example, if there is a User model with a related Address model, and the input is user_kwargs = dict( name='user', age=20, address=dict( city='city', state='ST', ), ) then passing this information in to the User constructor directly will fail, because User.address is a related model, not a simple field. I agree that most of the time you should want unexpected keyword arguments to raise an exception, but in specific circumstances it can be helpful to extract only the pieces of a dict that are relevant.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/