-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentation
Milestone
Description
First Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn't find it.
- I already read and followed all the documentation and didn't find an answer.
Description
Usage > Detail docs mention this:
If you are using Python 3.10 or above, you can take advantage of new syntax proposed in PEP 636 – Structural Pattern Matching to handle the result.
from meiga import Success, Failure, Error
class NoSuchKey(Error): ...
class TypeMismatch(Error): ...
match result:
case Success(_):
print(f"Success")
case Failure(NoSuchKey()):
print("Failure with NoSuchKey")
case Failure(TypeMismatch()):
print("Failure with TypeMismatch")
case _:
print("default")
While mostly convenient, this code does not work when the result
variable was constructed not with Failure(NoSuchKey())
but with Result(failure=NoSuchKey())
:
In [1]: from meiga import Result, Failure, Error, Success
In [2]: class NoSuchKey(Error): pass
In [3]: result = Result(failure=NoSuchKey())
In [4]: match result:
...: case Success(_):
...: print(f"Success")
...: case Failure(NoSuchKey()):
...: print("Failure with NoSuchKey")
...: case Failure(TypeMismatch()):
...: print("Failure with TypeMismatch")
...: case _:
...: print("default")
default
Getting rid of error types in case
statements does not help:
In [5]: result = Result(failure=Error())
In [6]: match result:
...: case Success(_):
...: print("Success")
...: case Failure(_):
...: print("Failure")
...: case _:
...: print("default")
default
match
and its magics are too new tech for me, so I cannot provide any insight on why isn't it working or what could be amended.
Operating System
Linux
Operating System Details
No response
meiga Version
1.8.3
Python Version
python --version
Additional Context
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentation