From cdda5ccd9f2e7d25f4b28285710109f4c4ef29f3 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 2 Feb 2023 18:48:23 -0800 Subject: [PATCH 1/4] Fix error caused by non-existent variable_frequency property --- adafruit_motor/stepper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_motor/stepper.py b/adafruit_motor/stepper.py index 1c29ee8..929dc43 100755 --- a/adafruit_motor/stepper.py +++ b/adafruit_motor/stepper.py @@ -114,7 +114,7 @@ def __init__( self._coil = (ain2, bin1, ain1, bin2) for i in range(4): if self._coil[i].frequency < 1500: - if not self._coil[i].variable_frequency: + if hasattr(self._coil[i], "variable_frequency") and not self._coil[i].variable_frequency: raise ValueError( "PWMOut outputs must either be set to at least " "1500 Hz or allow variable frequency." From 5fa3a28a38c3120184b331c53cfc51054790f81d Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 3 Feb 2023 07:41:31 -0800 Subject: [PATCH 2/4] Ran pre-commit --- adafruit_motor/stepper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/adafruit_motor/stepper.py b/adafruit_motor/stepper.py index 929dc43..421e0b5 100755 --- a/adafruit_motor/stepper.py +++ b/adafruit_motor/stepper.py @@ -114,7 +114,10 @@ def __init__( self._coil = (ain2, bin1, ain1, bin2) for i in range(4): if self._coil[i].frequency < 1500: - if hasattr(self._coil[i], "variable_frequency") and not self._coil[i].variable_frequency: + if ( + hasattr(self._coil[i], "variable_frequency") + and not self._coil[i].variable_frequency + ): raise ValueError( "PWMOut outputs must either be set to at least " "1500 Hz or allow variable frequency." From f3bfd6dd6a83c19128789726dfcf71b4857ea00b Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 3 Feb 2023 10:36:52 -0800 Subject: [PATCH 3/4] Use try/except instead of non-existent property --- adafruit_motor/stepper.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/adafruit_motor/stepper.py b/adafruit_motor/stepper.py index 421e0b5..9c02047 100755 --- a/adafruit_motor/stepper.py +++ b/adafruit_motor/stepper.py @@ -114,15 +114,13 @@ def __init__( self._coil = (ain2, bin1, ain1, bin2) for i in range(4): if self._coil[i].frequency < 1500: - if ( - hasattr(self._coil[i], "variable_frequency") - and not self._coil[i].variable_frequency - ): + try: + self._coil[i].frequency = 2000 + except AttributeError: raise ValueError( "PWMOut outputs must either be set to at least " "1500 Hz or allow variable frequency." ) - self._coil[i].frequency = 2000 if microsteps < 2: raise ValueError("Microsteps must be at least 2") if microsteps % 2 == 1: From 5a3cc7cc9fbdf70abcbf6cd2b3a4e6c1ea7fbbf8 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 3 Feb 2023 10:38:51 -0800 Subject: [PATCH 4/4] Chain the errors --- adafruit_motor/stepper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_motor/stepper.py b/adafruit_motor/stepper.py index 9c02047..3100d34 100755 --- a/adafruit_motor/stepper.py +++ b/adafruit_motor/stepper.py @@ -116,11 +116,11 @@ def __init__( if self._coil[i].frequency < 1500: try: self._coil[i].frequency = 2000 - except AttributeError: + except AttributeError as err: raise ValueError( "PWMOut outputs must either be set to at least " "1500 Hz or allow variable frequency." - ) + ) from err if microsteps < 2: raise ValueError("Microsteps must be at least 2") if microsteps % 2 == 1: