Skip to content

Commit

Permalink
Remove uses of hasElement
Browse files Browse the repository at this point in the history
  • Loading branch information
TimFelixBeyer committed Jul 8, 2023
1 parent d43ec76 commit 8141355
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions music21/analysis/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ def _extractNoteReductiveEvent(self, n, infoDict=None, removeAfterParsing=True):
return

removalIndices = []
if m.hasElement(n):
if n in m:
offset = n.getOffsetBySite(m)
else: # it is in a Voice
offset = 0.0
for v in m.voices:
if v.hasElement(n):
if n in v:
offset = n.getOffsetBySite(v)


Expand Down
4 changes: 2 additions & 2 deletions music21/freezeThaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,8 @@ def testSerializationScaffoldA(self):
sf.setupSerializationScaffold()

# test safety
self.assertTrue(s2.hasElement(n1))
self.assertTrue(s1.hasElement(n1))
self.assertTrue(n1 in s2)
self.assertTrue(n1 in s1)

def testJSONPickleSpanner(self):
from music21 import converter
Expand Down
7 changes: 4 additions & 3 deletions music21/stream/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,9 @@ def mergeAttributes(self, other: base.Music21Object):
'definesExplicitPageBreaks', '_atSoundingPitch', '_mutable'):
if hasattr(other, attr):
setattr(self, attr, getattr(other, attr))

@deprecated('v10', 'v11', 'use `obj in stream` instead')

@common.deprecated('v10', 'v11', 'Use `el in stream` instead of '
'`stream.hasElement(el)`')
def hasElement(self, obj: base.Music21Object) -> bool:
'''
Return True if an element, provided as an argument, is contained in
Expand Down Expand Up @@ -2008,7 +2009,7 @@ def _deepcopySubclassable(self: StreamType,
# must manually add elements to new Stream
for e in self._elements:
# environLocal.printDebug(['deepcopy()', e, 'old', old, 'id(old)', id(old),
# 'new', new, 'id(new)', id(new), 'old.hasElement(e)', old.hasElement(e),
# 'new', new, 'id(new)', id(new), 'e in old', e in old,
# 'e.activeSite', e.activeSite, 'e.getSites()', e.getSites(), 'e.getSiteIds()',
# e.getSiteIds()], format='block')
#
Expand Down
10 changes: 5 additions & 5 deletions music21/test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,14 @@ def testStoreLastDeepCopyOf(self):
n2 = copy.deepcopy(n1)
self.assertEqual(id(n2.derivation.origin), id(n1))

def testHasElement(self):
def testContains(self):
n1 = note.Note()
s1 = stream.Stream()
s1.append(n1)
s2 = copy.deepcopy(s1)
n2 = s2[0] # this is a new instance; not the same as n1
self.assertFalse(s2.hasElement(n1))
self.assertTrue(s2.hasElement(n2))
self.assertFalse(n1 in s2)
self.assertTrue(n2 in s2)

self.assertFalse(s1 in n2.sites)
self.assertTrue(s2 in n2.sites)
Expand Down Expand Up @@ -622,7 +622,7 @@ class Mock:
s.insert(i, el)

for ew in storage:
self.assertTrue(s.hasElement(ew))
self.assertTrue(ew in s)

match = [e.getOffsetBySite(s) for e in storage]
self.assertEqual(match, [0.0, 1.0])
Expand All @@ -648,7 +648,7 @@ def getnchannels(self):
s.insert(i, el)

for ew in storage:
self.assertTrue(s.hasElement(ew))
self.assertTrue(ew in s)

matchOffset = []
matchBeatStrength = []
Expand Down

0 comments on commit 8141355

Please sign in to comment.