Python Forum
in a function checking for caller errors
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
in a function checking for caller errors
#1
i have a function with a bunch of arguments, 3 of which have a lot of choices. i worry that it is easy for development of the calling code to make mistakes. so the function has thorough error checking. this error checking could, in some cases, be more extensive than the function's actions. what i am doing is adding a keyword argument defaulting to False that is bypass_error_checks=False for developers to use once they have tested their code so things will run faster. is this a reasonable thing to do?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
It doesn't look very nice because nobody expects that and the users will waste time understanding the consequences of setting this flag or not. Can you tell us what are the various choices and what error checks are performed by the function?
Reply
#3
the function runs a command pipeline ... a list of list of string. tuple can be used in place of list. bytes or bytearray can be used in place of str. it checks that valid types are used. it applies the checks over every item in every list. there is a keyword argument out= that specifies where output of the pipeline goes to, such as an open file or file name. there are a few other keywords and it also cross checks the combinations of settings.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
what about setting an environment variable to enable the maximum level of checks? the developer could leave that set when doing development. without it being set the function will assume this call is from well debugged code and that the checks would pass.

these checks are intended to meaningfully report to the developer what coding errors she has made.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  function to store in caller's context Skaperen 7 2,955 Jul-27-2020, 08:45 PM
Last Post: Skaperen
  f-string for caller? Skaperen 2 1,953 Sep-16-2019, 07:47 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020