Skip to content

Commit

Permalink
fix ruff errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 22, 2024
1 parent ec08228 commit b8489de
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 145 deletions.
12 changes: 6 additions & 6 deletions mytz/tree/tree_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@


def findZoneInfoDir():
for _dir in (
for dir_ in (
"/usr/share/zoneinfo",
"/usr/lib/zoneinfo",
"/usr/share/lib/zoneinfo",
"/etc/zoneinfo",
):
if os.path.isdir(_dir):
return _dir
if os.path.isdir(dir_):
return dir_

try:
import pytz
except ImportError:
pass
else:
_dir = os.path.join(os.path.dirname(pytz.__file__), "zoneinfo")
if os.path.isdir(_dir):
return _dir
dir_ = os.path.join(os.path.dirname(pytz.__file__), "zoneinfo")
if os.path.isdir(dir_):
return dir_

raise OSError("zoneinfo directory not found")

Expand Down
2 changes: 1 addition & 1 deletion plugins/pray_times_files/pray_times_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def __init__(
timeFormat="24h",
):
"""
timeFormat possible values:
TimeFormat possible values:
"24h"
"12h"
"12hNS": 12-hour format with no suffix
Expand Down
19 changes: 13 additions & 6 deletions scal3/account/starcal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from contextlib import suppress
from datetime import datetime
from typing import TYPE_CHECKING

from scal3 import event_lib
from scal3.cal_types import (
Expand All @@ -33,6 +34,10 @@
jsonTimeFromEpoch,
)

if TYPE_CHECKING:
from scal3.event_lib import Event, EventGroup


# def encodeDateTimeRuleValue(
# return {
# "date": dateEncode(self.date),
Expand Down Expand Up @@ -95,13 +100,15 @@ def _emptyDecoder(_ev):
}


def decodeRemoteEvent(remoteEventFull, accountId, _group):
def decodeRemoteEvent(
remoteEventFull: dict,
accountId: int,
_group: EventGroup,
) -> tuple[Event | None, str | None]:
"""
remoteEventFull is dict.
return (event, error)
Return (event, error)
where event is instance of event_lib.Event, or None
and error is string or None
and error is string or None.
"""
try:
eventType = remoteEventFull["eventType"]
Expand Down Expand Up @@ -172,7 +179,7 @@ def callBase(self, method, path, **kwargs):

def call(self, method, path, **kwargs):
"""
return (data, None) if successful
Return (data, None) if successful
return (data, error) if failed
where error is string and data is a dict.
"""
Expand Down
2 changes: 1 addition & 1 deletion scal3/cal_types/gregorian_proleptic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def getMonthNameAb(tr, m, y=None): # noqa: ARG001


def ifloor(x):
return int(floor(x))
return floor(x)


epoch = 1721426
Expand Down
4 changes: 2 additions & 2 deletions scal3/cal_types/hijri.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def getMonthNameAb(tr, m, y=None): # noqa: ARG001


def ifloor(x: float) -> int:
return int(floor(x))
return floor(x)


def iceil(x: float) -> int:
return int(ceil(x))
return ceil(x)


def save():
Expand Down
2 changes: 1 addition & 1 deletion scal3/cal_types/julian.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


def ifloor(x):
return int(floor(x))
return floor(x)


monthName = (
Expand Down
2 changes: 1 addition & 1 deletion scal3/date_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def getFloatYearFromJd(jd: int, calType: int) -> float:
def getJdFromFloatYear(fyear: float, calType: int) -> int:
if calType not in calTypes:
raise RuntimeError(f"cal type '{calType}' not found")
year = int(math.floor(fyear))
year = math.floor(fyear)
yearStartJd = to_jd(year, 1, 1, calType)
nextYearStartJd = to_jd(year + 1, 1, 1, calType)
dayOfYear = int((fyear - year) * (nextYearStartJd - yearStartJd))
Expand Down
76 changes: 38 additions & 38 deletions scal3/event_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ def scanDir(self, dpath: str) -> int:
if ext != ".json":
continue
try:
_id = int(idStr)
id_ = int(idStr)
except ValueError:
log.error(f"invalid file name: {dpath}")
continue
lastId = max(_id, lastId)
lastId = max(id_, lastId)
return lastId

def scan(self) -> None:
Expand Down Expand Up @@ -2271,7 +2271,7 @@ def getNotifyBeforeMin(self):

def setDefaults(self, group=None):
"""
sets default values that depends on event type and group type
Sets default values that depends on event type and group type
as well as common parameters, like those are set in __init__
should call this method from parent event class.
"""
Expand Down Expand Up @@ -2355,13 +2355,13 @@ def getTextParts(self, showDesc=True):
def getText(self, showDesc=True):
return "".join(self.getTextParts(showDesc))

def setId(self, _id=None):
if _id is None or _id < 0:
_id = lastIds.event + 1 # FIXME
lastIds.event = _id
elif _id > lastIds.event:
lastIds.event = _id
self.id = _id
def setId(self, id_=None):
if id_ is None or id_ < 0:
id_ = lastIds.event + 1 # FIXME
lastIds.event = id_
elif id_ > lastIds.event:
lastIds.event = id_
self.id = id_
self.file = self.getFile(self.id)
# self.filesDir = join(self.dir, "files")
self.loadFiles()
Expand Down Expand Up @@ -3935,7 +3935,7 @@ def moveDown(self, index):

def remove(self, event: Event): # call when moving to trash
"""
excludes event from this container (group or trash),
Excludes event from this container (group or trash),
not delete event data completely
and returns the index of (previously contained) event.
"""
Expand Down Expand Up @@ -3967,7 +3967,7 @@ def setData(self, data) -> None:

def getEventNoCache(self, eid: int) -> Event:
"""
no caching. and no checking if group contains eid
No caching. and no checking if group contains eid
used only for sorting events.
"""
event = EventContainer._getEvent(self, eid)
Expand Down Expand Up @@ -4313,20 +4313,20 @@ def getLastSync(self) -> int | None:

def setDefaults(self) -> None:
"""
sets default values that depends on group type
Sets default values that depends on group type
not common parameters, like those are set in __init__.
"""

def __bool__(self) -> bool:
return self.enable # FIXME

def setId(self, _id: int | None = None) -> None:
if _id is None or _id < 0:
_id = lastIds.group + 1 # FIXME
lastIds.group = _id
elif _id > lastIds.group:
lastIds.group = _id
self.id = _id
def setId(self, id_: int | None = None) -> None:
if id_ is None or id_ < 0:
id_ = lastIds.group + 1 # FIXME
lastIds.group = id_
elif id_ > lastIds.group:
lastIds.group = id_
self.id = id_
self.file = self.getFile(self.id)

def setTitle(self, title: str) -> None:
Expand Down Expand Up @@ -5010,7 +5010,7 @@ def getWeeklyScheduleData(
currentWeekOnly: bool = False,
) -> list[list[list[dict[str, Any]]]]:
"""
returns `data` as a nested list that:
Returns `data` as a nested list that:
data[weekDay][classIndex] = WeeklyScheduleItem(name, weekNumMode)
where
weekDay: int, in range(7)
Expand Down Expand Up @@ -5828,18 +5828,18 @@ def setData(self, data: list[int]) -> None:
for sid in data:
if not isinstance(sid, int) or sid == 0:
raise RuntimeError(f"unexpected {sid=}, {self=}")
_id = sid
_id = abs(sid)
id_ = sid
id_ = abs(sid)
try:
cls = getattr(classes, self.childName).main
obj = cls.load(self.fs, _id)
obj = cls.load(self.fs, id_)
except Exception:
log.error(f"error loading {self.childName}")
log.exception("")
continue
obj.parent = self
obj.enable = sid > 0
self.idList.append(_id)
self.idList.append(id_)
self.byId[obj.id] = obj

def getData(self) -> list[int]:
Expand Down Expand Up @@ -6139,22 +6139,22 @@ def loadData(self, _id: int) -> dict[str, Any]:

# FIXME: types
def getLoadedObj(self, obj: DummyAccount) -> Account:
_id = obj.id
data = self.loadData(_id)
id_ = obj.id
data = self.loadData(id_)
name = data["type"]
cls = self.loadClass(name)
if cls is None:
return
obj = cls(_id)
obj = cls(id_)
obj.fs = self.fs
data = self.loadData(_id)
data = self.loadData(id_)
obj.setData(data)
return obj

def replaceDummyObj(self, obj: DummyAccount) -> Account:
_id = obj.id
id_ = obj.id
obj = self.getLoadedObj(obj)
self.byId[_id] = obj
self.byId[id_] = obj
return obj


Expand Down Expand Up @@ -6298,13 +6298,13 @@ def save(self):
self.setId()
BsonHistEventObj.save(self)

def setId(self, _id=None):
if _id is None or _id < 0:
_id = lastIds.account + 1 # FIXME
lastIds.account = _id
elif _id > lastIds.account:
lastIds.account = _id
self.id = _id
def setId(self, id_=None):
if id_ is None or id_ < 0:
id_ = lastIds.account + 1 # FIXME
lastIds.account = id_
elif id_ > lastIds.account:
lastIds.account = id_
self.id = id_
self.file = self.getFile(self.id)

def stop(self):
Expand Down
6 changes: 3 additions & 3 deletions scal3/interval_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def simplifyNumList(
minCount: int = 3,
) -> list[int | tuple[int, int]]:
"""
nums must be sorted
Nums must be sorted
minCount >= 2.
"""
ranges = []
Expand All @@ -63,7 +63,7 @@ def getIntervalPoints(
lst_index: int = 0,
) -> list[tuple[int, int, int]]:
"""
lst is a list of (start, end, closedEnd) or (start, end) tuples
Lst is a list of (start, end, closedEnd) or (start, end) tuples
start (int)
end (int)
closedEnd (bool).
Expand Down Expand Up @@ -136,7 +136,7 @@ def normalizeIntervalList(lst):

def humanizeIntervalList(lst):
"""
replace Closed End intervals with 2 new intervals
Replace Closed End intervals with 2 new intervals
in math terms: [a, b] ==> [a, b) + [b, b].
lst is a list of (start, end, closedEnd) tuples
Expand Down
2 changes: 1 addition & 1 deletion scal3/moon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def getMoonPhase(jd, southernHemisphere=False):
"""
returns a float number that: 0 <= phase < 2
Returns a float number that: 0 <= phase < 2
0.0 = no moon
1.0 = full moon.
"""
Expand Down
2 changes: 1 addition & 1 deletion scal3/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def getUserDisplayName():

def kill(pid, signal=0):
"""
sends a signal to a process
Sends a signal to a process
returns True if the pid is dead
with no signal argument, sends no signal.
"""
Expand Down
Loading

0 comments on commit b8489de

Please sign in to comment.