From 70db215c637fc283bd3bf168025f82c8eb58e0a3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sat, 26 Oct 2024 10:30:41 -0500 Subject: [PATCH 1/2] fix null error from label property / resize --- .pre-commit-config.yaml | 2 +- .pylintrc | 2 +- adafruit_button/button_base.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..374676d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + rev: v3.3.1 hooks: - id: pylint name: pylint (library code) diff --git a/.pylintrc b/.pylintrc index f945e92..fe3f21d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -361,7 +361,7 @@ valid-metaclass-classmethod-first-arg=mcs [DESIGN] # Maximum number of arguments for function / method -max-args=5 +max-args=18 # Maximum number of attributes for a class (see R0902). # max-attributes=7 diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index bcebc7e..030f3d6 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -78,7 +78,9 @@ def __init__( @property def label(self): """The text label of the button""" - return self._label.text + if self._label is not None and hasattr(self._label, "text"): + return self._label.text + return None @label.setter def label(self, newtext): From e3e4c242138dfd4169323418ac05c384d5e5b79e Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 13 Nov 2024 15:50:47 -0600 Subject: [PATCH 2/2] use getattr --- adafruit_button/button_base.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_button/button_base.py b/adafruit_button/button_base.py index 030f3d6..8a7709c 100644 --- a/adafruit_button/button_base.py +++ b/adafruit_button/button_base.py @@ -78,9 +78,7 @@ def __init__( @property def label(self): """The text label of the button""" - if self._label is not None and hasattr(self._label, "text"): - return self._label.text - return None + return getattr(self._label, "text", None) @label.setter def label(self, newtext):