From 6977a1a9c3b4432ded8b90c06cbfebc25919a4c0 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Wed, 10 Feb 2021 20:30:53 -0800 Subject: [PATCH 1/3] Change assert to if in get_pin() Replace assert stmt with if stmt raising a ValueError if pin number is out of bounds. --- adafruit_mcp230xx/mcp23008.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_mcp230xx/mcp23008.py b/adafruit_mcp230xx/mcp23008.py index b6fe20a..7de2476 100644 --- a/adafruit_mcp230xx/mcp23008.py +++ b/adafruit_mcp230xx/mcp23008.py @@ -85,5 +85,6 @@ def get_pin(self, pin): """Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this MCP23008 device. """ - assert 0 <= pin <= 7 + if not 0 <= pin <= 7: + raise ValueError("Pin number must be 0-7.") return DigitalInOut(pin, self) From 44471b71a272bc5688a22ccd753a1cbeb45bcca3 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Wed, 10 Feb 2021 20:36:03 -0800 Subject: [PATCH 2/3] mcp23016.py - Change assert to if in get_pin() Removed assert stmt and added if stmt returning a ValueError if pin number is out of bounds. --- adafruit_mcp230xx/mcp23016.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_mcp230xx/mcp23016.py b/adafruit_mcp230xx/mcp23016.py index 3fcdbf5..a68306b 100644 --- a/adafruit_mcp230xx/mcp23016.py +++ b/adafruit_mcp230xx/mcp23016.py @@ -126,7 +126,8 @@ def get_pin(self, pin): """Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this MCP23016 device. """ - assert 0 <= pin <= 15 + if not 0 <= pin <= 15: + raise ValueError("Pin number must be 0-15.") return DigitalInOut(pin, self) def clear_inta(self): From 1334c4d288192455ff0366e5e5489b6baa57c2c8 Mon Sep 17 00:00:00 2001 From: PRC-SAK Date: Wed, 10 Feb 2021 20:46:36 -0800 Subject: [PATCH 3/3] mcp23017.py - Change assert to if in get_pin() Removed assert stmt and added if stmt returning a ValueError if pin number is out of bounds. --- adafruit_mcp230xx/mcp23017.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_mcp230xx/mcp23017.py b/adafruit_mcp230xx/mcp23017.py index c4d67c1..4ab3e1c 100644 --- a/adafruit_mcp230xx/mcp23017.py +++ b/adafruit_mcp230xx/mcp23017.py @@ -163,7 +163,8 @@ def get_pin(self, pin): """Convenience function to create an instance of the DigitalInOut class pointing at the specified pin of this MCP23017 device. """ - assert 0 <= pin <= 15 + if not 0 <= pin <= 15: + raise ValueError("Pin number must be 0-15.") return DigitalInOut(pin, self) @property