DEV Community

Discussion on: Python exceptions considered an anti-pattern

Collapse
 
defman profile image
Sergey Kislyakov
Failure(4).map(lambda number: number / 2)
# => Failure(2)

Looks like .map got executed for a Failure. Is it a bug?

Also, does PyCharm handle @safe decorator properly? I mean, if I have a function something() -> User, do I get auto-completions for User and not [User, WhateverExcetpion]?

Collapse
 
sobolevn profile image
Nikita Sobolev

Sorry, that's a typo! And thanks for noticing. I have updated this line:

Failure(4).map(lambda number: number / 2)
# => Failure(4)

PyCharm resolves types correctly, since we are shipping PEP561 annotations.