-
Notifications
You must be signed in to change notification settings - Fork 58
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
Type Support for argparse.Namespace() #200
Comments
Reasonable request for |
I'm not sure I can see how class Namespace(_AttributeHolder):
"""Simple object for storing attributes.
Implements equality by attribute names and values, and provides a simple
string representation.
"""
def __init__(self, **kwargs):
for name in kwargs:
setattr(self, name, kwargs[name]) Do you have an example of how validation would work? |
Hi @Viicos, you bring up a good point. I am not very familiar with the internals of pydantic and also the namespace class. I tried to add I believe the error message said to try to add a validation of that type to pydantic, but I don't know how to do that. I thought I would raise a ticket instead. I can maybe look more into this, but it's not my area of expertise. I do find it interesting though that if you put the dictionary version of the I was thinking having support for cli arguments built into pydantic would be really nice to make making cli applications easier. Especially, making it easier to configure cli input types and commands using like types rather than specifying a lot of strings in dictionaries and stuff.
I can try to put together an example for validation as you asked. Do you have a good resource on how to do this though? I am not sure I fully understand what should go into like default validation. |
Hello,
I hope you are well. I really like Pydantic, and I've found it makes it much easier and also neater to work with classes in python.
Today, I tried to use it to put the arguments parsed from the command line with argparse as an attribute in class to use composition. The exact type name is argparse.Namespace. Because this wasn't able to work, I just converted the arguments to a default dictionary type and used that with pedantic.
This works, but I think it would be much nicer to have the argparse type be able to work work pydantic classes by default, this way I can use the built-in functionality of that, rather than just using dictionary keys to get the arguments.
Would it be possible to add this?
Thanks!
The text was updated successfully, but these errors were encountered: