Skip to content

Commit

Permalink
Merge pull request sympy#20590 from oscarbenjamin/pr_basic_slots
Browse files Browse the repository at this point in the history
fix(core): use __slots__ for DefaultPrinting and Basic
  • Loading branch information
oscarbenjamin authored Dec 12, 2020
2 parents cffd4e0 + 7c1516f commit c060059
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sympy/core/_print_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Printable:
This also adds support for LaTeX printing in jupyter notebooks.
"""

# Since this class is used as a mixin we set empty slots. That means that
# instances of any subclasses that use slots will not need to have a
# __dict__.
__slots__ = ()

# Note, we always use the default ordering (lex) in __str__ and __repr__,
# regardless of the global setting. See issue 5487.
def __str__(self):
Expand Down
6 changes: 6 additions & 0 deletions sympy/core/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def test_structure():
assert bool(b1)


def test_immutable():
assert not hasattr(b1, '__dict__')
with raises(AttributeError):
b1.x = 1


def test_equality():
instances = [b1, b2, b3, b21, Basic(b1, b1, b1), Basic]
for i, b_i in enumerate(instances):
Expand Down

0 comments on commit c060059

Please sign in to comment.