Posts: 4,558
Threads: 1,463
Joined: Sep 2016
i have a function which has keyword arguments for everything. two of them also could be given as regular positional arguments. it tests for something non-None given both ways for each. the intent is to raise an exception when the call is done wrong like this. which exception should i raise for this?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,558
Threads: 1,463
Joined: Sep 2016
Jun-20-2020, 11:03 PM
(This post was last modified: Jun-20-2020, 11:07 PM by Skaperen.)
(Jun-20-2020, 08:45 AM)Gribouillis Wrote: Can you give an example of such code?
def foobar(*args,**kwargs):
if len(args)>1 and 'foo' in kwargs:
raise Foo('"foo" is given in both positional arguments (arg 2) and keyword arguments (foo=)')
...
(Jun-20-2020, 11:01 AM)ndc85430 Wrote: Why would you do that instead of either using one or the other?
sometimes i want to use it one way or sometimes i want to use it the other way. i plan to post (a URL to) this code when it is done and initially tested.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,558
Threads: 1,463
Joined: Sep 2016
so, basically, the function being called the wrong way, is treating it as a type other than what it really is. i found a more like example
random.choices() when used with an argument provided twice, raised TypeError, too. that's what i'll use.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.