-
-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
preparser + match-case = sadness #34678
Comments
comment:1
As a workaround, you can use |
comment:2
I think this should be solved by defining |
comment:3
Something like this?
(taken from that link) That seems to work for this case, at least. |
comment:4
How broadly could this be done? For |
comment:5
One option is to modify diff --git a/src/sage/structure/element.pyx b/src/sage/structure/element.pyx
index b5d83ef71b..11981b1b7c 100644
--- a/src/sage/structure/element.pyx
+++ b/src/sage/structure/element.pyx
@@ -397,6 +397,25 @@ cdef class Element(SageObject):
"""
self._parent = parent
+ # __match_args__ and __match_self_prop__ are to handle Python's
+ # match-case construction. See :trac:`34678` and
+ # https://peps.python.org/pep-0634/#class-patterns.
+ __match_args__ = ("__match_self_prop__",)
+
+ @property
+ def __match_self_prop__(self):
+ """
+ TESTS::
+
+ sage: x = 2
+ sage: match x:
+ ....: case 1: print('hello')
+ ....: case 2: print('world')
+ ....:
+ world
+ """
+ return self
+
def _set_parent(self, parent):
r"""
Set the parent of ``self`` to ``parent``. |
comment:6
The above patch doesn't work, and I think that I really don't understand the
Why doesn't the match-case block raise an error, since |
comment:7
In fact I get this behavior in plain Python. I guess this is binding the undefined symbol
It accepts Sage |
comment:8
|
comment:9
The difference is that |
comment:10
I think we would be able to handle |
comment:11
That may be more of a job than I have time for right now. |
Component: python3
Issue created by migration from https://trac.sagemath.org/ticket/34678
The text was updated successfully, but these errors were encountered: