question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve handling of kwargs

See original GitHub issue

Update: There seem to be four degrees of possible kwarg handling:

  1. Use wild card **kwargs for all key word arguments. This is currently done, e.g. in Flow. Currently, this is the most common way in oemof.

  2. Define known kwargs but set empty defaults. Technically, this is the same API as in 1. but it improves readability and comfort. This way was suggested later in this ticket. It also reduces the likeliness of typos.

  3. Enforce values for obligatory quantities. This would also improve readability, and would also solve copy and paste errors, typos, etc. It would require programmers to make explicit when obligatory parameters should be left uninitialized (e.g. Sink(inputs={})). It is already implemented in ExtractionTurbineCHP but quite uncommon in oemof.

  4. Disallow faulty kwargs (like outputs for a Sink, or those including typos). This option would either cost flexibility, require some “expert mode” where strict enforcement is turned off, or need explicit checks. (Option 4 is what I originally proposed here.)

Original text: I would suggest to raise errors if unknown kwargs are passed to functions. I believe this would make it greatly easier to debug code using oemof and improve the usability.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
uvchikcommented, Jan 29, 2019

Personally, I think we should put more stuff out of kwargs into named parameters.

  1. I agree that mandatory parameters shouldn’t be hidden in kwargs. This would also solve some of @p-snft 's problems. If a Sink does not have an input parameter an error is raised even if there is an iMput or an output parameter instead.

  2. We could also think of forbidden attributes. A Source for example is not allowed to have an input parameter and a Sink is not allowed to have an output parameter.

Anything else?

@oemof/oemof-developer-group What do you think?

0reactions
p-snftcommented, Mar 6, 2020

The check should solve the known problems. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper way to use **kwargs in Python - Stack Overflow
I like to use positional arguments only for required arguments, and kwargs for arguments that may or may not be specified, but it...
Read more >
Stop Abusing *args and **kwargs in Python | by Eden Au
*args allows you to pass an arbitrary number of positional arguments to your function. The asterisk * is an unpacking parameter. They are...
Read more >
10 Examples to Master *args and **kwargs in Python
The *args and **kwargs make it easier and cleaner to handle arguments. The important parts are “*” and “**”.
Read more >
Python args and kwargs: Demystified
In this step-by-step tutorial, you'll learn how to use args and kwargs in Python to add more flexibility to your functions. You'll also...
Read more >
How To Use *args and **kwargs in Python 3 - DigitalOcean
When programming, you may not be aware of all the possible use cases of your code, and may want to offer more options...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found