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

extra kwargs raises exemption #4420

Closed
c-wilson opened this issue May 12, 2015 · 4 comments
Closed

extra kwargs raises exemption #4420

c-wilson opened this issue May 12, 2015 · 4 comments

Comments

@c-wilson
Copy link

I have a simple suggestion that I would be happy to implement if there is agreement: Can we NOT raise exemptions when unknown kwargs are passed to a plotting function (ie plot, scatter)? My understanding is that most APIs use _args and *_kwargs in function definitions so that they won't crash if they get extra arguments.

@WeatherGod
Copy link
Member

Why would you want to not raise an exception if something is incorrect? We already have a problem where we don't do enough input validation, so various arguments get silently lost. There are some functions that do pass-through keywords, but they really should be the exception and not the norm (it makes it difficult to know if everything has been validated).

@tacaswell
Copy link
Member

The expand a bit on what @WeatherGod said, we use **kwargs heavily to allow the user to pass kwargs through to the underlying Artist objects. For example, in the scatter case any kwargs that scatter does not explicitly use are used to update the Collection object before it is returned. If there is a kwarg which is not a valid property of the Collection object the correct thing to do is to raise to alert the user that invalid input was passed in. The alternative is to silently pass misspelling (for example the user meant to type lw=5, but typed lq=5 silently passing could make it very hard to sort out why the line width is not changing, where as raising and saying 'lq is not valid' makes it very easy).

I am strongly 👎 on this (and would like things to raise more exceptions earlier for invalid input).

@tacaswell tacaswell added this to the unassigned milestone May 12, 2015
@WeatherGod
Copy link
Member

By the way, if you are looking to write error-free code: https://pypi.python.org/pypi/fuckit/4.8.0

@c-wilson
Copy link
Author

ok, no problem, I agree with your arguments. I was wrapping plot functions, and I guess was being a bit lazy by just passing _args and *_kwargs. Closed.

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

No branches or pull requests

3 participants