diff --git a/.github/workflows/python-lint.yml b/.github/workflows/python-lint.yml index d62fab0..643bd12 100644 --- a/.github/workflows/python-lint.yml +++ b/.github/workflows/python-lint.yml @@ -3,7 +3,7 @@ name: Lint check -on: [pull_request, push] +on: [pull_request] jobs: test: diff --git a/py_src/gpiod/__init__.py b/py_src/gpiod/__init__.py index 112a1ee..7032e65 100644 --- a/py_src/gpiod/__init__.py +++ b/py_src/gpiod/__init__.py @@ -79,7 +79,7 @@ def make_chip_iter() -> chip_iter: for c in make_chip_iter(): print(c.label) """ - return chip_iter().__iter__() + return iter(chip_iter()) class line_iter(libgpiodcxx.line_iter): diff --git a/py_src/gpiod/libgpiod/__init__.py b/py_src/gpiod/libgpiod/__init__.py index adc8de0..209a0a4 100644 --- a/py_src/gpiod/libgpiod/__init__.py +++ b/py_src/gpiod/libgpiod/__init__.py @@ -64,7 +64,7 @@ def _is_gpiochip_cdev(path: str) -> bool: # Do we have a corresponding sysfs attribute? name = basename(path) - sysfsp = "/sys/bus/gpio/devices/{}/dev".format(name) + sysfsp = f"/sys/bus/gpio/devices/{name}/dev" if not access(sysfsp, R_OK): # This is a character device but not the one we're after. # Before the introduction of this function, we'd fail with @@ -76,10 +76,10 @@ def _is_gpiochip_cdev(path: str) -> bool: # Make sure the major and minor numbers of the character device # correspond to the ones in the dev attribute in sysfs. - devstr = "{}:{}".format(major(statbuf.st_rdev), minor(statbuf.st_rdev)) + devstr = f"{major(statbuf.st_rdev)}:{minor(statbuf.st_rdev)}" try: - with open(sysfsp, "r") as fd: + with open(sysfsp, "r", encoding="utf-8") as fd: sysfsdev = fd.read(len(devstr)) except FileNotFoundError: return False @@ -307,10 +307,10 @@ def _line_bulk_all_free(bulk: gpiod_line_bulk) -> bool: def _line_request_direction_is_valid(direction: int) -> bool: - if ( - direction == GPIOD_LINE_REQUEST_DIRECTION_AS_IS - or direction == GPIOD_LINE_REQUEST_DIRECTION_INPUT - or direction == GPIOD_LINE_REQUEST_DIRECTION_OUTPUT + if direction in ( + GPIOD_LINE_REQUEST_DIRECTION_AS_IS, + GPIOD_LINE_REQUEST_DIRECTION_INPUT, + GPIOD_LINE_REQUEST_DIRECTION_OUTPUT, ): return True @@ -563,7 +563,7 @@ def gpiod_line_is_requested(line: gpiod_line) -> bool: @return True if given line was requested, false otherwise. """ - return line.state == _LINE_REQUESTED_VALUES or line.state == _LINE_REQUESTED_EVENTS + return line.state in (_LINE_REQUESTED_VALUES, _LINE_REQUESTED_EVENTS) def gpiod_line_is_free(line: gpiod_line) -> bool: diff --git a/py_src/gpiod/libgpiodcxx/__init__.py b/py_src/gpiod/libgpiodcxx/__init__.py index 6d0d269..0c92194 100644 --- a/py_src/gpiod/libgpiodcxx/__init__.py +++ b/py_src/gpiod/libgpiodcxx/__init__.py @@ -135,7 +135,7 @@ def open(self, device: Union[int, str], how: int = _CHIP_OPEN_LOOKUP) -> None: raise OSError( errno, strerror(errno), - "cannot open GPIO device {}".format(device), + f"cannot open GPIO device {device}", ) self._m_chip = shared_chip(chip_struct) @@ -981,9 +981,7 @@ def request(self, config: line_request, default_vals: Optional[List[int]] = None default_vals = [0] * self.size if self.size != len(default_vals): - raise ValueError( - "the number of default values must correspond " "to the number of lines" - ) + raise ValueError("the number of default values must correspond to the number of lines") try: for i in range(self.size): @@ -1035,7 +1033,7 @@ def set_values(self, values: List[int]) -> None: self._throw_if_empty() if self.size != len(values): - raise ValueError("the size of values array must correspond to " "the number of lines") + raise ValueError("the size of values array must correspond to the number of lines") for i in range(self.size): self._m_bulk[i].set_value(values[i]) @@ -1054,7 +1052,7 @@ def set_config(self, direction: int, flags: int, values: Optional[List[int]] = N self._throw_if_empty() if values is not None and self.size != len(values): - raise ValueError("the size of values array must correspond to " "the number of lines") + raise ValueError("the size of values array must correspond to the number of lines") gflags = 0 @@ -1123,7 +1121,7 @@ def set_direction_output(self, values: Optional[List[int]] = None) -> None: self._throw_if_empty() if values is not None and self.size != len(values): - raise ValueError("the size of values array must correspond to " "the number of lines") + raise ValueError("the size of values array must correspond to the number of lines") bulk = libgpiod.gpiod_line_bulk() diff --git a/py_src/gpiod/test/bulk_button.py b/py_src/gpiod/test/bulk_button.py index 1d585bd..8009c78 100644 --- a/py_src/gpiod/test/bulk_button.py +++ b/py_src/gpiod/test/bulk_button.py @@ -36,7 +36,7 @@ config.request_type = BUTTON_EDGE for i in range(buttons.size): - config.consumer = "Button {}".format(i) + config.consumer = f"Button {i}" buttons[i].request(config) diff --git a/py_src/gpiod/test/sequential_blink.py b/py_src/gpiod/test/sequential_blink.py index 637017a..e5658c0 100644 --- a/py_src/gpiod/test/sequential_blink.py +++ b/py_src/gpiod/test/sequential_blink.py @@ -28,7 +28,7 @@ config.request_type = line_request.DIRECTION_OUTPUT for i in range(leds.size): - config.consumer = "Blink{}".format(i) + config.consumer = f"Blink {i}" leds.get(i).request(config) print("line: ", leds[i].offset, ", consumer: ", leds[i].consumer) diff --git a/pyproject.toml b/pyproject.toml index e78db6d..38b13f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -278,7 +278,7 @@ min-public-methods = 2 [tool.pylint.exceptions] # Exceptions that will emit a warning when caught. -overgeneral-exceptions = ["BaseException", "Exception"] +overgeneral-exceptions = ["builtins.BaseException", "builtins.Exception"] [tool.pylint.format] # Expected format of line ending, e.g. empty (any line ending), LF or CRLF. @@ -298,7 +298,7 @@ indent-string = " " max-line-length = 100 # Maximum number of lines in a module. -max-module-lines = 1000 +max-module-lines = 2000 # Allow the body of a class to be on the same line as the declaration if body # contains single statement. @@ -376,6 +376,9 @@ disable = [ "use-symbolic-message-instead", "missing-class-docstring", "invalid-name", + "broad-exception-raised", + "too-many-public-methods", + "duplicate-code", ] # Enable the message, report, category or checker with the given id(s). You can