-
Notifications
You must be signed in to change notification settings - Fork 206
Allow extra arguments to ic call #150
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
base: master
Are you sure you want to change the base?
Conversation
|
@gruns can you take a look at this? |
|
I still think this is an useful non-intrusive addition, I still apply the pr every time I install the package *if you want extra explanations or use cases, I'm available to provide |
|
hey @Joaq33! thank you for the incessant pokes and follow-ups! theyre always helpful 🙏 lets back up a bit and see if this is the best solution to the problem here. instead of adding why? because i think the better solution here is to add those arguments, explicitly, to why? because it strikes me as poor API design to accept arbitrary kwargs that may, or may not, have meaning. for example, if you call |
|
You are right, I revisited this pr and it's wrong. I will upload another tested version in the future based on the same idea. For example: ic(l, someMadeUpParam='lolsup')will output: and it's traceback. Here is another example but now using a custom defined outputFunction with optional arguments, I will include it as a test too def testOutputFunctionKwargs(self):
lst = []
def appendTo(s, optional=False):
if optional:
lst.append(s + 'with_option')
return
lst.append(s)
with configureIcecreamOutput(ic.prefix, appendTo):
with captureStandardStreams() as (out, err):
ic(a)
assert not out.getvalue() and not err.getvalue()
with configureIcecreamOutput(outputFunction=appendTo):
with captureStandardStreams() as (out, err):
ic(b, optional=True)
assert not out.getvalue() and not err.getvalue()
pairs = parseOutputIntoPairs(out, '\n'.join(lst), 2)
assert pairs == [[('a', '1')], [('b', '2with_option')]]This will allow conditional printing, log levels, and other conditionals with the same ic configuration. Thank you for your attention and feedback. |
|
Wouldn't it be better to check (with inspect.Signature) if all of the kwargs are indeed in the signature. If not, raise an exception at configure time. Best of both worlds ... |
|
@ruudvanderham can you provide an example of what you mean? how would this work if both functions - @Joaq33 another option would be to add a single new param to so zooming out, the problem to address here is
correct? i want to make sure we're on the same page with the problem so we can arrive at the best solution 🙂 |
|
Rather than answering from @ruudvanderham, I answer from my other GitHub account (@salabim). Can you provide an example of what you mean? how would this work if both functions - ic() and argToStringFunction() - just accept kwargs and process them internally? |
|
hey @salabim! yep! helpful. thank you! 🙂 that said, I'm not a fan of this approach because it places an arbitrary requirement on the
why? because this, in turn, would be an extra requirement users of icecream would have to know, and remember, when adopting a custom and, in turn, I'm not a fan of this design additionally, this design doesnt 'scale' because there are multiple configurable functions ic.configureOutput(prefix, outputFunction, argToStringFunction, includeContext, contextAbsPath)and perhaps more in the future. notably among them: so if you add a parameter like so! what's a better design. one design i dont like would be to add separate ic(foo, argToStrFnParams={'limitColors': False}, outputFnParams={'format':True})but this is crazy verbose. so also not a fan of this another, less verbose approach, would be to have a single downside of this? cant check for explicit params with cc @Jakeroid |
This change allows you to add extra keyworded arguments to your ic function call.
This solves a problem that I faced when I wanted my list prints to be customized, but ic didn't allow me to change the argToStringFunction's optional arguments. As an example, the default function that works in the background to format the input, pprint.pformat, could accept the optional arguments such as compact, but ic doesn't handle those.
Code:
Output:
Also, this supports the usage of kwargs in user created argToStringFunction
*I hope you like it, this is my first open source contribution