Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
refactor: fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
hhk7734 committed Apr 23, 2023
1 parent e95979c commit c2fea15
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

name: Lint check

on: [pull_request, push]
on: [pull_request]

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion py_src/gpiod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 8 additions & 8 deletions py_src/gpiod/libgpiod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
12 changes: 5 additions & 7 deletions py_src/gpiod/libgpiodcxx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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])
Expand All @@ -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

Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion py_src/gpiod/test/bulk_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion py_src/gpiod/test/sequential_blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c2fea15

Please sign in to comment.