microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
44 stars 25 forks source link

`SoundEffect` `fx` parameter, `fx` attribute, and `None` #130

Closed microbit-carlos closed 2 years ago

microbit-carlos commented 2 years ago

SoundEffect.FX_NONE is 0:

>>> SoundEffect.FX_NONE
0

SoundEffect(fx=SoundEffect.FX_NONE).fx returns None:

>>> str(SoundEffect(fx=SoundEffect.FX_NONE).fx)
'None'

But the fx parameter cannot be set to None:

>>> SoundEffect(fx=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert NoneType to int

But the fx attribute can:

>>> effect = SoundEffect()
>>> effect.fx = 0
>>> str(effect.fx)
'None'
>>> effect.fx = None
>>> str(effect.fx)
'None'

This is the only parameter that can set to "None" and it was originally specified like that to avoid having to create an extra constant and qstring. However, it makes sense to keep the SoundEffect.FX_NONE constant, so maybe we should remove the SoundEffect internal logic that converts 0 to None?

dpgeorge commented 2 years ago

Yes this None behaviour was from an earlier implementation and it would be good to get rid of it, for simplicity and consistency.

Done in 7dc7030095a858ff8e8751a35e870925e323fc22