Skip to content

Commit d33ca93

Browse files
committed
Add function signature; straighten import issue
1 parent 21a4080 commit d33ca93

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

mathics/builtin/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
PatternObject,
2121
)
2222

23+
from mathics.core.pattern import pattern_objects
24+
2325
from mathics.settings import ENABLE_FILES_MODULE
2426
from mathics.version import __version__ # noqa used in loading to check consistency.
2527

@@ -267,7 +269,6 @@ def sanity_check(cls, module):
267269
mathics_to_python = {} # here we have: name -> string
268270
sympy_to_mathics = {}
269271

270-
pattern_objects = {}
271272
builtins_precedence = {}
272273

273274
new_builtins = _builtins

mathics/core/evaluators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
)
2222
from mathics.core.convert.sympy import from_sympy
2323
from mathics.core.definitions import PyMathicsLoadException
24+
from mathics.core.element import BaseElement
2425
from mathics.core.evaluation import Evaluation
2526
from mathics.core.expression import Expression
2627
from mathics.core.number import PrecisionValueError, get_precision
27-
from mathics.core.symbols import Atom, BaseElement
28+
from mathics.core.symbols import Atom
2829
from mathics.core.systemsymbols import SymbolMachinePrecision, SymbolN
2930

3031

mathics/core/list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(
4141
# call_frame = inspect.getouterframes(curframe, 2)
4242
# print("caller name:", call_frame[1][3])
4343

44-
# from mathics.core.symbols import BaseElement
44+
# from mathics.core.element import BaseElement
4545
# for element in elements:
4646
# if not isinstance(element, BaseElement):
4747
# from trepan.api import debug; debug()

mathics/core/pattern.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# cython: profile=False
33
# -*- coding: utf-8 -*-
44

5+
from typing import Optional
56

67
from mathics.core.atoms import Integer
7-
from mathics.core.element import ensure_context
8+
from mathics.core.element import BaseElement, ensure_context
9+
from mathics.core.evaluation import Evaluation
810
from mathics.core.expression import Expression, SymbolDefault
911
from mathics.core.symbols import Atom, Symbol, symbol_set
1012
from mathics.core.systemsymbols import (
@@ -41,6 +43,8 @@
4143
SymbolRepeatedNull,
4244
)
4345

46+
pattern_objects = {}
47+
4448

4549
class StopGenerator(Exception):
4650
"""
@@ -73,15 +77,12 @@ class Pattern:
7377
"""
7478

7579
@staticmethod
76-
def create(expr):
80+
def create(expr: BaseElement) -> "Pattern":
7781
"""
78-
Creates an AtomPattern or an ExpressionPattern or a
79-
(builtin) pattern object according
80-
to the class of the parameter `expr`.
82+
If ``expr`` is listed in ``pattern_object`` return the pattern found there.
83+
Otherwise, if ``expr`` is an ``Atom``, create and return ``AtomPattern`` for ``expr``.
84+
Otherwise, create and return and ``ExpressionPattern`` for ``expr``.
8185
"""
82-
from mathics.builtin import pattern_objects
83-
84-
# from mathics.core.pattern import AtomPattern, ExpressionPattern
8586

8687
name = expr.get_head_name()
8788
pattern_object = pattern_objects.get(name)
@@ -114,7 +115,14 @@ def match(
114115
"""
115116
raise NotImplementedError
116117

117-
def does_match(self, expression, evaluation, vars=None, fully=True):
118+
def does_match(
119+
self,
120+
expression: BaseElement,
121+
evaluation: Evaluation,
122+
vars=Optional[dict],
123+
fully: bool = True,
124+
) -> bool:
125+
118126
"""
119127
returns True if `expression` matches self.
120128
"""

0 commit comments

Comments
 (0)