Skip to content

Commit 4be98fc

Browse files
committed
merge
2 parents b81ccb8 + c54808f commit 4be98fc

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

CHANGES.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. contents::
22

33
CHANGES
4-
=======
4+
*******
55

66
5.0.3dev0
77
---------
@@ -52,7 +52,8 @@ Bugs
5252
# ``0`` with a given precision (like in ```0`3```) is now parsed as ``0``, an integer number.
5353
#. ``RandomSample`` with one list argument now returns a random ordering of the list items. Previously it would return just one item.
5454
#. Rules of the form ``pat->Condition[expr, cond]`` are handled as in WL. The same works for nested `Condition` expressions. Also, comparisons among these rules was improved.
55-
55+
#. ``mathics.core.Pattern.create`` now catches the case when the input parameter is not an `Atom` or an `Expression`.
56+
5657

5758
Enhancements
5859
++++++++++++

mathics/builtin/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,11 @@ def get_string_value(self):
826826

827827
def sameQ(self, expr) -> bool:
828828
"""Mathics SameQ"""
829+
if expr is self:
830+
return True
831+
# Otherwise, we need to convert
832+
# self into an to expression
833+
# to avoid an infinite loop...
829834
return self.to_expression().sameQ(expr)
830835

831836
def do_format(self, evaluation, format):

mathics/core/pattern.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ def create(expr: BaseElement) -> "Pattern":
8686
by calling the method ``to_expression``, and then call the function
8787
again with this new object as input.
8888
"""
89-
if not isinstance(expr, (Atom, Expression)):
90-
expr = expr.to_expression()
91-
9289
name = expr.get_head_name()
9390
pattern_object = pattern_objects.get(name)
9491
if pattern_object is not None:
@@ -97,8 +94,10 @@ def create(expr: BaseElement) -> "Pattern":
9794
return AtomPattern(expr)
9895
elif isinstance(expr, Expression):
9996
return ExpressionPattern(expr)
100-
# Otherwise, try to get an expression and
101-
# call again.
97+
# To handle Boxes and other possible objects that
98+
# can be converted into expressions, convert expr to
99+
# expression and call this function
100+
# again:
102101
return Pattern.create(expr.to_expression())
103102

104103
def match(

0 commit comments

Comments
 (0)