Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
SupportView.__eq__, __ne__: New
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Sep 11, 2022
1 parent 026d8a5 commit a417411
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/sage/structure/support_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from collections.abc import MappingView, Sequence, Set

from sage.misc.superseded import deprecation


class SupportView(MappingView, Sequence, Set):
r"""
Expand Down Expand Up @@ -135,3 +137,41 @@ def __contains__(self, key):
if zero is None:
return bool(value)
return value != zero

def __eq__(self, other):
r"""
TESTS::
sage: d = {1: 17, 2: 0}
sage: from sage.structure.support_view import SupportView
sage: supp = SupportView(d); supp
SupportView({1: 17, 2: 0})
sage: supp == [1]
doctest:warning...
DeprecationWarning: comparing a SupportView with a list is deprecated
See https://trac.sagemath.org/34509 for details.
True
"""
if isinstance(other, list):
deprecation(34509, 'comparing a SupportView with a list is deprecated')
return list(self) == other
return NotImplemented

def __ne__(self, other):
r"""
TESTS::
sage: d = {1: 17, 2: 0}
sage: from sage.structure.support_view import SupportView
sage: supp = SupportView(d); supp
SupportView({1: 17, 2: 0})
sage: supp != [1]
doctest:warning...
DeprecationWarning: comparing a SupportView with a list is deprecated
See https://trac.sagemath.org/34509 for details.
False
"""
if isinstance(other, list):
deprecation(34509, 'comparing a SupportView with a list is deprecated')
return list(self) != other
return NotImplemented

0 comments on commit a417411

Please sign in to comment.