Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feedback on module
#2
Function arguments are seldom checked in python, but there is a place where they are often checked: the standard library! (at least the functions implemented in C). So we cannot say that this is fundamentally unpythonic. It depends on the use case. I would check what the values should be rather than what they should not be, so for example, with more explicit name and message
from numbers import Number

def _fail_unless_non_negative_number(*kwargs):
    for k, v in kwargs.items():
        if not (isinstance(v, Number) and (v >= 0)):
            raise TypeError(('Expected non negative number for parameter', k, 'got', repr(v)))
Reply


Messages In This Thread
Feedback on module - by GamePatrol - Mar-06-2018, 01:34 AM
RE: Feedback on module - by Gribouillis - Mar-06-2018, 07:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Feedback on my first Python module CodeRaker 11 6,790 Jun-21-2018, 02:16 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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