Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiz committed Aug 15, 2023
1 parent 915fc87 commit 27de4df
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 47 deletions.
20 changes: 15 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
[project.optional-dependencies]
dev = [
"black>=23.3.0",
"ruff>=0.0.275",
"ruff>=0.0.284",
"coverage>=7.2.5",
]

Expand All @@ -56,18 +56,21 @@ select = [
"UP", # pyupgrade
"YTT", # flake8-2020
"ANN", # flake8-annotations
"ASYNC", # flake8-async
"S", # flake8-bandit
"BLE", # flake8-blind-except
# "FBT", # flake8-boolean-trap
"B", # flake8-bugbear
"A", # flake8-builtins
"COM", # flake8-commas
"CPY", # flake8-copyright
"C4", # flake8-comprehensions
"DTZ", # flake8-datetimez
"T10", # flake8-debugger
"DJ", # flake8-django
"EM", # flake8-errmsg
"EXE", # flake8-executable
"FA", # flake8-future-annotations
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
"G", # flake8-logging-format
Expand All @@ -80,34 +83,41 @@ select = [
"RSE", # flake8-raise
"RET", # flake8-return
"SLF", # flake8-self
"SLOT", # flake8-slots
"SIM", # flake8-simplify
"TID", # flake8-tidy-imports
"TCH", # flake8-type-checking
"INT", # flake8-gettext
"ARG", # flake8-unused-arguments
"PTH", # flake8-use-pathlib
# "TD", # flake-todos
# "FIX", # flake-fixme
# "ERA", # eradicate
"PD", # pandas-vet
"PGH", # pygrep-hooks
"PLC", # pylint convention
"PLE", # pylint error
"PLR", # pylint refactor
"PLW", # pylint warning
# "TRY", # tryceratops
"FLY", # flynt
"NPY", # numpy-specific
"AIR", # airflow-specific
"PERF", # performance
"RUF", # ruff-specific
]
ignore = [
"E501", # line-too-long -- disabled as black takes care of this
"N802", # invalid-function-name -- too late!
"COM812", # missing-trailing-comma -- conflicts with black?
"N802", # invalid-function-name -- too late!
"N818", # error-suffix-on-exception-name -- too late!
"D415", # ends-in-punctuation -- too aggressive
"EM101", # raw-string-in-exception -- no thanks
"EM102", # f-string-in-exception -- no thanks
"N818", # error-suffix-on-exception-name -- too late!
"ANN101", # missing-type-self -- unnecessary
"ANN102", # missing-type-cls -- unnecessary
"PLR0913", # too-many-arguments -- no thanks
"D105", # undocumented-magic-method -- no thanks
"ANN101", # missing-type-self -- unnecessary
"ANN102", # missing-type-cls -- unnecessary
]

[tool.ruff.pydocstyle]
Expand Down
10 changes: 2 additions & 8 deletions src/gkeepapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,7 @@ def dump(self) -> dict:
nodes = []
for node in self.all():
nodes.append(node)
for child in node.children:
nodes.append(child)
nodes.extend(node.children)
return {
"keep_version": self._keep_version,
"labels": [label.save(False) for label in self.labels()],
Expand Down Expand Up @@ -1205,13 +1204,8 @@ def _findDirtyNodes(self) -> list[_node.Node]:
if child.id not in self._nodes:
self._nodes[child.id] = child

nodes = []
# Collect all dirty nodes (any nodes from above will be caught too).
for node in self._nodes.values():
if node.dirty:
nodes.append(node)

return nodes
return [node for node in self._nodes.values() if node.dirty]

def _clean(self) -> None:
"""Recursively check that all nodes are reachable."""
Expand Down
52 changes: 18 additions & 34 deletions src/gkeepapi/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,11 @@ def save(self, clean: bool = True) -> dict:
@classmethod
def _generateAnnotationId(cls) -> str:
return "{:08x}-{:04x}-{:04x}-{:04x}-{:012x}".format(
random.randint( # noqa: suspicious-non-cryptographic-random-usage
0x00000000, 0xFFFFFFFF
),
random.randint( # noqa: suspicious-non-cryptographic-random-usage
0x0000, 0xFFFF
),
random.randint( # noqa: suspicious-non-cryptographic-random-usage
0x0000, 0xFFFF
),
random.randint( # noqa: suspicious-non-cryptographic-random-usage
0x0000, 0xFFFF
),
random.randint( # noqa: suspicious-non-cryptographic-random-usage
0x000000000000, 0xFFFFFFFFFFFF
),
random.randint(0x00000000, 0xFFFFFFFF), # noqa: S311
random.randint(0x0000, 0xFFFF), # noqa: S311
random.randint(0x0000, 0xFFFF), # noqa: S311
random.randint(0x0000, 0xFFFF), # noqa: S311
random.randint(0x000000000000, 0xFFFFFFFFFFFF), # noqa: S311
)


Expand Down Expand Up @@ -724,7 +714,7 @@ def str_to_dt(cls, tzs: str) -> datetime.datetime:
)

@classmethod
def int_to_dt(cls, tz: int | float) -> datetime.datetime:
def int_to_dt(cls, tz: float) -> datetime.datetime:
"""Convert a unix timestamp into an object.
Params:
Expand Down Expand Up @@ -1056,9 +1046,7 @@ def _generateId(cls, tz: float) -> str:
return "tag.{}.{:x}".format(
"".join(
[
random.choice( # noqa: suspicious-non-cryptographic-random-usage
"abcdefghijklmnopqrstuvwxyz0123456789"
)
random.choice("abcdefghijklmnopqrstuvwxyz0123456789") # noqa: S311
for _ in range(12)
]
),
Expand Down Expand Up @@ -1216,9 +1204,7 @@ def __init__(
self.server_id = None
self.parent_id = parent_id
self.type = type_
self._sort = random.randint( # noqa: suspicious-non-cryptographic-random-usage
1000000000, 9999999999
)
self._sort = random.randint(1000000000, 9999999999) # noqa: S311
self._version = None
self._text = ""
self._children = {}
Expand All @@ -1233,9 +1219,7 @@ def __init__(
def _generateId(cls, tz: float) -> str:
return "{:x}.{:016x}".format(
int(tz * 1000),
random.randint( # noqa: suspicious-non-cryptographic-random-usage
0x0000000000000000, 0xFFFFFFFFFFFFFFFF
),
random.randint(0x0000000000000000, 0xFFFFFFFFFFFFFFFF), # noqa: S311
)

def _load(self, raw: dict) -> None:
Expand Down Expand Up @@ -1701,7 +1685,7 @@ def text(self, value: str) -> None:
self.touch(True)

def __str__(self) -> str:
return "\n".join([self.title, self.text])
return f"{self.title}\n{self.text}"


class List(TopLevelNode):
Expand Down Expand Up @@ -1766,6 +1750,8 @@ def sorted_items(cls, items: list[ListItem]) -> list[ListItem]: # noqa: C901
class T(tuple):
"""Tuple with element-based sorting"""

__slots__ = ()

def __cmp__(self, other: "T") -> int:
for a, b in itertools.zip_longest(self, other):
if a != b:
Expand Down Expand Up @@ -1820,9 +1806,7 @@ def sort_items(
reverse: Whether to reverse the output.
"""
sorted_children = sorted(self._items(), key=key, reverse=reverse)
sort_value = random.randint( # noqa: suspicious-non-cryptographic-random-usage
1000000000, 9999999999
)
sort_value = random.randint(1000000000, 9999999999) # noqa: S311

for node in sorted_children:
node.sort = sort_value
Expand Down Expand Up @@ -2186,10 +2170,10 @@ def from_json(raw: dict) -> Node | None:


if DEBUG: # pragma: no cover
Node.__load = Node._load # noqa: private-member-access
Node.__load = Node._load # noqa: SLF001

def _load(self, raw): # noqa: missing-type-function-argument
self.__load(raw) # : private-member-access
self._find_discrepancies(raw) # : private-member-access
def _load(self, raw): # noqa: ANN001, ANN202
self.__load(raw)
self._find_discrepancies(raw)

Node._load = _load # noqa: private-member-access
Node._load = _load # noqa: SLF001

0 comments on commit 27de4df

Please sign in to comment.