Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
Post image 6
Post image 7
Post image 8
Post image 9
Post image 10
Post image 11
Post image 12
1 / 12
0

Stop Letting Python Functions Lie to You: Introducing explicit-result

DEV Community·chukwunwike obodo·about 1 month ago
#u61G4w2d
Reading 0:00
15s threshold

Python is beautiful, readable, and highly expressive. But its built-in error handling mechanism, exceptions, has a fundamental flaw: Exceptions are invisible. Take a look at this standard Python function signature: def get_user ( user_id : int ) -> User : ... Enter fullscreen mode Exit fullscreen mode What does this signature tell you? It promises to return a User . But does it? What happens if the database connection drops? What if user_id doesn't exist? What if there's a permission issue? You can’t know without digging into the implementation, hoping the docstrings are accurate, or waiting for a surprise stack trace in production. The type system provides zero guarantees about what can fail. That’s where explicit-result comes in. The Philosophy of explicit-result explicit-result is a zero-dependency, fully-typed Python library that brings Result and Option primitives to your Python code. It is designed around three core ideas: Errors should be part of the contract.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More