Repository navigation
Fix TypeError sorting Orderless patterns that mix atoms and literal expressions #1991
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -480,7 +480,14 @@ def __init__( | |
|
|
||
| def _build_pattern_sort_key(self) -> tuple: | ||
| if self.isliteral: | ||
| return (BASIC_LITERAL_EXPRESSION_PATTERN_SORT_KEY, self.expr.element_order) | ||
| # Keep the shape of BASIC_ATOM_PATTERN_SORT_KEY (magic, int, ...): | ||
| # atoms share the magic number, so the second slot must be an int | ||
| # here too, or sorting an Orderless pattern mixing both fails. | ||
| return ( | ||
| BASIC_LITERAL_EXPRESSION_PATTERN_SORT_KEY, | ||
| 1, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of magic number 1, we should define a constant like BASIC_LITERAL_EXPRESSION_SECOND_SLOT = 1 in |
||
| self.expr.element_order, | ||
| ) | ||
| return ( | ||
| BASIC_EXPRESSION_PATTERN_SORT_KEY, | ||
| self.head.pattern_precedence, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,9 @@ def test_dispatch(str_expr, msgs, str_expected, fail_msg): | |
| ("f[10]", None, "100", None), | ||
| ("f[10, Power -> 3]", None, "1000", None), | ||
| ("Clear[f]", None, None, None), | ||
| # Orderless literal pattern mixing an atom and an expression | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and on 179, it would be nice to put this comment inside the assert fail message ( |
||
| ("f[2 x[3]] = 1; f[2 x[3]]", None, "1", None), | ||
| ("Clear[f]", None, None, None), | ||
| ], | ||
| ) | ||
| def test_pattern(str_expr, msgs, str_expected, fail_msg): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.