- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 802
 
Description
What is the problem?
The problem has been reported several times already, so I'm late to the party (here fore example #979).
To recap, assert keyword is not to be used as proposed in the example of the episode of Defensive Programming. The reason has been pointed out several times with various degrees of detail, but it boils down to that is basically a debug and testing phase tool, that can be bypassed at runtime by the interpreter. Python documentation states that basically evaluates to:
if __debug__:
    if not expression: raise AssertionErrorThe episode of Defensive Programming focuses mainly on input validation. Input validation needs to stop the program every time an incorrect input is passed. if raise blocks are the standard and canonical way of doing this. For an example see this function in the scipy repository:
https://github.com/scipy/scipy/blob/v1.14.0/scipy/optimize/_minimize.py#L53-L775
I do not propose to also add the idea of exceptions neither try except blocks, since a novice user will not need this, I simple propose to replace assert blocks with if raise blocks. I will provide a pull request of this in the coming days.