diff --git a/music21/musicxml/m21ToXml.py b/music21/musicxml/m21ToXml.py index 1cd97f14e..e85c9e423 100644 --- a/music21/musicxml/m21ToXml.py +++ b/music21/musicxml/m21ToXml.py @@ -1077,7 +1077,7 @@ def pageLayoutToXmlPrint(self, pageLayout, mxPrintIn=None): setb(pageLayout, mxPrint, 'page-number') mxPageLayout = self.pageLayoutToXmlPageLayout(pageLayout) - if mxPageLayout: + if len(mxPageLayout): mxPrint.append(mxPageLayout) if mxPrintIn is None: @@ -1104,7 +1104,7 @@ def pageLayoutToXmlPageLayout(self, pageLayout, mxPageLayoutIn=None): mxPageMargins = Element('page-margins') for direction in ('left', 'right', 'top', 'bottom'): seta(pageLayout, mxPageMargins, direction + '-margin') - if mxPageMargins: + if len(mxPageMargins): mxPageLayout.append(mxPageMargins) if mxPageLayoutIn is None: @@ -1158,7 +1158,7 @@ def systemLayoutToXmlPrint(self, systemLayout, mxPrintIn=None): mxSystemLayout = Element('system-layout') self.systemLayoutToXmlSystemLayout(systemLayout, mxSystemLayout) - if mxSystemLayout: + if len(mxSystemLayout): mxPrint.append(mxSystemLayout) if mxPrintIn is None: @@ -1204,7 +1204,7 @@ def systemLayoutToXmlSystemLayout(self, systemLayout, mxSystemLayoutIn=None): for direction in ('top', 'bottom', 'left', 'right'): seta(systemLayout, mxSystemMargins, direction + '-margin') - if mxSystemMargins: + if len(mxSystemMargins): mxSystemLayout.append(mxSystemMargins) seta(systemLayout, mxSystemLayout, 'system-distance', 'distance') @@ -2505,7 +2505,7 @@ def setTitles(self) -> None: firstTitleFound = titles[0] mxWorkTitle = SubElement(mxWork, 'work-title') mxWorkTitle.text = str(titles[0]) - if mxWork: + if len(mxWork): mxScoreHeader.append(mxWork) movementNumbers: tuple[metadata.Text, ...] = mdObj['movementNumber'] @@ -4942,7 +4942,7 @@ def noteToNotations( for x in (mxArticulations, mxTechnicalMark, mxOrnaments): - if x: + if x is not None: notations.append(x) # TODO: dynamics in notations diff --git a/music21/musicxml/partStaffExporter.py b/music21/musicxml/partStaffExporter.py index 872471346..94bec24a1 100644 --- a/music21/musicxml/partStaffExporter.py +++ b/music21/musicxml/partStaffExporter.py @@ -575,10 +575,9 @@ def isMultiAttribute(m21Class: type[M21ObjType], # Initial PartStaff in group: find earliest mxAttributes, set clef #1 and if initialPartStaffRoot is None: initialPartStaffRoot = self.getRootForPartStaff(ps) - mxAttributes = initialPartStaffRoot.find('measure/attributes') - clef1: Element | None = mxAttributes.find('clef') if mxAttributes else None - if clef1 is not None: - clef1.set('number', '1') + if (mxAttributes := initialPartStaffRoot.find('measure/attributes')) is not None: + if (clef1 := mxAttributes.find('clef')) is not None: + clef1.set('number', '1') mxStaves = Element('staves') mxStaves.text = str(len(group)) @@ -591,11 +590,11 @@ def isMultiAttribute(m21Class: type[M21ObjType], if multiKey and mxAttributes is not None: key1 = mxAttributes.find('key') - if key1: + if key1 is not None: key1.set('number', '1') if multiMeter and mxAttributes is not None: meter1 = mxAttributes.find('time') - if meter1: + if meter1 is not None: meter1.set('number', '1') # Subsequent PartStaffs in group: set additional clefs on mxAttributes @@ -631,10 +630,7 @@ def isMultiAttribute(m21Class: type[M21ObjType], ) if multiMeter: - oldMeter: Element | None = thisPartStaffRoot.find( - 'measure/attributes/time' - ) - if oldMeter: + if (oldMeter := thisPartStaffRoot.find('measure/attributes/time')) is not None: oldMeter.set('number', str(staffNumber)) helpers.insertBeforeElements( mxAttributes, @@ -642,8 +638,7 @@ def isMultiAttribute(m21Class: type[M21ObjType], tagList=['staves'] ) if multiKey: - oldKey: Element | None = thisPartStaffRoot.find('measure/attributes/key') - if oldKey: + if (oldKey := thisPartStaffRoot.find('measure/attributes/key')) is not None: oldKey.set('number', str(staffNumber)) helpers.insertBeforeElements( mxAttributes, diff --git a/music21/musicxml/xmlToM21.py b/music21/musicxml/xmlToM21.py index ef09ac222..857fd25ad 100644 --- a/music21/musicxml/xmlToM21.py +++ b/music21/musicxml/xmlToM21.py @@ -2844,7 +2844,7 @@ def xmlToChord(self, mxNoteList: list[ET.Element]) -> chord.ChordBase: notes.append(self.xmlToSimpleNote(mxNote, freeSpanners=False)) c: chord.ChordBase - if any(mxNote.find('unpitched') for mxNote in mxNoteList): + if any(mxNote.find('unpitched') is not None for mxNote in mxNoteList): c = percussion.PercussionChord(notes) else: c = chord.Chord(notes) # type: ignore # they are all Notes.