-
Notifications
You must be signed in to change notification settings - Fork 16
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
Improve add_signature_parameters
: add first_possible
and last_possible
#82
Comments
Is there any scenario where you wouldn't want |
On second thought, I am rethinking my position. Explicit is better than implicit after all. I think changing |
Yes this is basically what I had in mind: users thinking that |
You are correct. I was still in the mindset of smarie/python-pytest-cases#279, where the current error is not easy to understand. However, that is because it is an internal issue with pytest-cases creating invalid signature that are opaque to the user of pytest-cases. If we update pytest-cases to use the new |
How should this be handled in the case where parameters are of different kinds? It's fairly obvious how |
Yes, I guess that the "conctract" should be based on the most intuitive behaviour for users. So for example
So I guess the easiest way to proceed would be to handle each parameter one by one |
I can implement this, but tbh I'm not sure how valuable this feature will be. I think we may be better off resolving smarie/python-pytest-cases#279 directly in pytest-cases rather than trying to add this functionality. The problem that I see is that, except in very special cases like pytest tests where pytest is handling function parameters via its own dependency injection mechanisms, it is generally not very useful to modify a function signature without knowing the exact desired result a priori. Wouldn't it make more sense to put the onus on the calling code to figure out what the first or last valid position is? That way the calling code also actually knows what valid ways to call the function are. Otherwise, there's no guarantee that a user creating a function in this way will have enough information about the signature to use it correctly afterwards. For instance, they could easily pass parameters in the wrong order. |
I think adding a keyword-only argument with a default is almost always safe, unless there is an existing argument of the same name. Supporting that case seems useful. It also seems reasonable that makefun would figure out where it's safe to insert an argument and put it there. |
I agree, this could be made to work for a keyword-only parameter. My concern applies more to positional or positional-or-keyword parameters, where the calling code can't make assumptions about the resulting API so it doesn't seem very useful. Maybe we should implement this and just restrict this to keyword-only parameters, then. Does that sound reasonable to both of you @lucaswiman @smarie? If we do go in that direction, this won't really address the original problem in smarie/python-pytest-cases#279, but I think that's OK. |
Thanks to both of you ! To be honest I think that it would be a little sad not to solve the original issue here. It seems to me that trying to restrict the scope of the feature will actually make the implementation (and documentation) more difficult to do. For
and the "secret sauce" could be in Maybe one way to start could be to write a few tests first, to be sure we agree on what this should do ? @vyasr if solving the initial pytest-cases issue is the priority on your side, then I suggest that you create a PR directly in pytest-cases, that would solve only that specific situation, so that we have a bit more time to elaborate a PR here in makefun all together. Indeed in makefun there is not much emergency in my opinion. What do you think ? |
No worries, my workaround is perfectly sufficient for now so I'm happy to try to resolve this first.
Yes, this is how I started and what made me ask all these questions. I am happy to put together an implementation early next week in a draft PR that we can iterate on. |
Sometimes adding a parameter at the beginning or end of parameters list would make the resulting signature invalid. Typically, adding a keyword-only parameter before a keyword-or-positional, or adding a parameter without default after a parameter with a default (and conversely)...
Two new arguments
first_possible
andlast_possible
could allow the users to ask for a "smart insert first" and "smart insert last" feature.This would help solving smarie/python-pytest-cases#279
in a reusable way.
The text was updated successfully, but these errors were encountered: