'NoneType' object has no attribute 'non_empty_length'

Hey there—I’m getting an error when I call Score.show() or Score.show_xml() in a SCAMP project I’m currently working on:

Traceback (most recent call last):
File “/Users/aes/Documents/Workspace/GitHub/duo-axis/sequence.py”, line 92, in
score.show()
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 719, in show
abjad().show(self.to_abjad(wrap_as_file=True, non_score_blocks=non_score_blocks, **lilypond_file_args))
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 1274, in to_abjad
return ScoreComponent.to_abjad(self, wrap_as_file=wrap_as_file, non_score_blocks=non_score_blocks,
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 565, in to_abjad
return self._to_abjad_lilypond_file(non_score_blocks=non_score_blocks, **lilypond_file_args)
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 597, in _to_abjad_lilypond_file
abjad_object = self._to_abjad()
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 1044, in _to_abjad
key_points, guide_marks = self._get_tempo_key_points_and_guide_marks()
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 1002, in _get_tempo_key_points_and_guide_marks
score_length = self.length()
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 876, in length
return max(staff.length() for staff in self.staves)
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 876, in
return max(staff.length() for staff in self.staves)
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 1629, in length
return sum(m.length for m in self.measures[:-1]) + self.measures[-1].non_empty_length()
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 1722, in non_empty_length
return max(v.non_empty_length() for v in self.voices)
File “/Users/aes/.virtualenvs/comp/lib/python3.9/site-packages/scamp/score.py”, line 1722, in
return max(v.non_empty_length() for v in self.voices)
AttributeError: ‘NoneType’ object has no attribute ‘non_empty_length’

I’ve been trying to chase down the change I made to my code which would have caused this but haven’t had any luck yet… just thought I’d ask if this rings any bells and a certain type of behavior is likely to be the culprit? Thanks!

And… it suddenly stopped breaking! Just now, I was making a few tweaks to the piece, and now I can get score output just fine. I don’t know if this is a known issue but I’d be happy to try to recreate if not.

Hey Alex!

I have some idea of what the culprit might be. In the process of creating a score, there’s a point in which each measure get represented as a list of voices, and empty voices get represented by None. It seems like there’s a bug where it’s trying to call non_empty_length on each of the voices in the last measure (I think it’s trying to figure out how long the part is), and running into a None value.

My guess is I just need to change: max(v.non_empty_length() for v in self.voices) to max(v.non_empty_length() for v in self.voices if v is not None), but if you can put together a version of your code that breaks, that would be helpful!