Skip to content

Commit d9bc4a5

Browse files
authored
Merge pull request #243 from Midnighter/feat/slots
refactor: turn Symbol & Dummy into cdefs
2 parents 7b158d2 + 38e3795 commit d9bc4a5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

symengine/lib/symengine_wrapper.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ cdef object c2py(rcp_const_basic o):
6363
elif (symengine.is_a_Symbol(deref(o))):
6464
if (symengine.is_a_PySymbol(deref(o))):
6565
return <object>(deref(symengine.rcp_static_cast_PySymbol(o)).get_py_object())
66-
r = Expr.__new__(Symbol)
66+
r = Symbol.__new__(Symbol)
6767
elif (symengine.is_a_Constant(deref(o))):
6868
r = S.Pi
6969
if (symengine.eq(deref(o), deref(r.thisptr))):
@@ -1110,7 +1110,7 @@ cdef class Expr(Basic):
11101110
pass
11111111

11121112

1113-
class Symbol(Expr):
1113+
cdef class Symbol(Expr):
11141114

11151115
"""
11161116
Symbol is a class to store a symbolic variable with a given name.
@@ -1155,7 +1155,7 @@ class Symbol(Expr):
11551155
return self.__class__
11561156

11571157

1158-
class Dummy(Symbol):
1158+
cdef class Dummy(Symbol):
11591159

11601160
def __init__(Basic self, name=None, *args, **kwargs):
11611161
if name is None:

symengine/tests/test_symbol.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ def test_symbol():
88
assert str(x) == "x"
99
assert str(x) != "y"
1010
assert repr(x) == str(x)
11+
# Verify the successful use of slots.
12+
assert not hasattr(x, "__dict__")
13+
assert not hasattr(x, "__weakref__")
1114

1215

1316
def test_symbols():
@@ -148,6 +151,7 @@ def test_has_symbol():
148151
assert not has_symbol(c, a)
149152
assert has_symbol(a+b, b)
150153

154+
151155
def test_dummy():
152156
x1 = Symbol('x')
153157
x2 = Symbol('x')
@@ -159,3 +163,6 @@ def test_dummy():
159163
assert xdummy1 != xdummy2
160164
assert Dummy() != Dummy()
161165
assert Dummy('x') != Dummy('x')
166+
# Verify the successful use of slots.
167+
assert not hasattr(xdummy1, "__dict__")
168+
assert not hasattr(xdummy1, "__weakref__")

0 commit comments

Comments
 (0)