Skip to content

Commit

Permalink
fix or ignore SIM102 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Mar 2, 2024
1 parent c1d6d88 commit 47c9e8e
Show file tree
Hide file tree
Showing 25 changed files with 227 additions and 230 deletions.
5 changes: 2 additions & 3 deletions plugins/pray_times_files/pray_times.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,8 @@ def shouldShowDisclaimer(self) -> bool:
return True

hyear, hmonth, hday = hijri.jd_to(getCurrentJd())
if hmonth == 9: # Ramadan
if dt > hday * 24 * 3600:
return True
if hmonth == 9 and dt > hday * 24 * 3600: # Ramadan
return True

return False

Expand Down
2 changes: 1 addition & 1 deletion plugins/pray_times_files/pray_times_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def entry_changed(self, entry):
def run(self):
ex = gtk.Dialog.run(self)
self.hide()
if ex == gtk.ResponseType.OK:
if ex == gtk.ResponseType.OK: # noqa: SIM102
if (
self.checkbEdit.get_active() or self.treev.get_cursor()[0] is not None
): # FIXME
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ lint.select = [
"EXE", # flake8-executable
"FA", # flake8-future-annotations
"ISC", # flake8-implicit-str-concat
"ICN", # flake8-import-conventions
# "G", # flake8-logging-format
"INP", # flake8-no-pep420
"PIE", # flake8-pie
Expand Down Expand Up @@ -79,7 +78,6 @@ lint.ignore = [
"PGH003", # Use specific rule codes when ignoring type issues
"PT027", # Use `pytest.raises` instead of unittest-style `assertRaises`, why?
"PD011", # Use `.to_numpy()` instead of `.values`, WTF?
"ICN001", # `tkinter` should be imported as `tk`, WTF?
"RUF005", # Consider `[*_list, x]` instead of concatenation
"PT009", # Use a regular `assert` instead of unittest-style `assertEqual`, why?
"PLR0911", # Too many return statements (x > 6)
Expand Down Expand Up @@ -125,8 +123,6 @@ lint.ignore = [

"RET502", # Do not implicitly `return None` in function able to return non-`None` value

"SIM102", # Use a single `if` statement instead of nested `if` statements

# S: global
"S101", # Use of `assert` detected
]
Expand Down Expand Up @@ -181,6 +177,7 @@ lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.lint.per-file-ignores]
"scripts/*.py" = [
"T201", # `print` found
"SIM",
]
"tools/*.py" = [
"T201", # `print` found
Expand Down
17 changes: 9 additions & 8 deletions scal3/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ def getWeekDayAuto(

# week number in year
def getWeekNumberByJdAndYear(jd: int, year: int) -> int:
if primary_to_jd(year + 1, 1, 1) - jd < 7: # FIXME
if getWeekNumber(*jd_to_primary(jd + 14)) == 3:
return 1
if (
primary_to_jd(year + 1, 1, 1) - jd < 7 and
getWeekNumber(*jd_to_primary(jd + 14)) == 3
):
return 1
###
absWeekNum, weekDay = getWeekDateFromJd(jd)
(
Expand All @@ -287,11 +289,10 @@ def getWeekNumberByJdAndYear(jd: int, year: int) -> int:
) = getWeekDateFromJd(primary_to_jd(year, 1, 1))
weekNum = absWeekNum - ystartAbsWeekNum + 1
###
if weekNumberMode < 7:
if ystartWeekDay > (weekNumberMode - firstWeekDay) % 7:
weekNum -= 1
if weekNum == 0:
weekNum = getWeekNumber(*jd_to_primary(jd - 7)) + 1
if weekNumberMode < 7 and ystartWeekDay > (weekNumberMode - firstWeekDay) % 7:
weekNum -= 1
if weekNum == 0:
weekNum = getWeekNumber(*jd_to_primary(jd - 7)) + 1
###
return weekNum

Expand Down
51 changes: 24 additions & 27 deletions scal3/event_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,8 @@ def save(self, *args) -> None:
if allReadOnly:
log.info(f"events are read-only, ignored file {self.file}")
return
if hasattr(self, "uuid"):
if self.uuid is None:
self.set_uuid()
if hasattr(self, "uuid") and self.uuid is None:
self.set_uuid()
return BsonHistObj.save(self, *args)


Expand Down Expand Up @@ -1059,9 +1058,9 @@ def calcOccurrence(
calType,
)
jd += (self.weekDay - jwday(jd)) % 7
if self.wmIndex == 4: # Last (Fouth or Fifth)
if jd_to(jd, calType)[1] != month:
jd -= 7
# Last (Fouth or Fifth)
if self.wmIndex == 4 and jd_to(jd, calType)[1] != month:
jd -= 7
if startJd <= jd < endJd:
jds.add(jd)
return JdOccurSet(jds)
Expand Down Expand Up @@ -1986,9 +1985,8 @@ def checkRulesDependencies(
rulesOd = self.rulesOd.copy()
if newRule:
rulesOd[newRule.name] = newRule
if disabledRule:
if disabledRule.name in rulesOd:
del rulesOd[disabledRule.name]
if disabledRule and disabledRule.name in rulesOd:
del rulesOd[disabledRule.name]
provideList = []
for ruleName, rule in rulesOd.items():
provideList.append(ruleName)
Expand Down Expand Up @@ -2332,12 +2330,11 @@ def getDescription(self):
def getTextParts(self, showDesc=True):
summary = self.getSummary()
##
if self.timeZoneEnable and self.timeZone:
if natz.gettz(self.timeZone) is None:
invalidTZ = _("Invalid Time Zone: {timeZoneName}").format(
timeZoneName=self.timeZone,
)
summary = "(" + invalidTZ + ")" + summary
if self.timeZoneEnable and self.timeZone and natz.gettz(self.timeZone) is None:
invalidTZ = _("Invalid Time Zone: {timeZoneName}").format(
timeZoneName=self.timeZone,
)
summary = "(" + invalidTZ + ")" + summary
####
description = self.getDescription()
if showDesc and description:
Expand Down Expand Up @@ -4849,9 +4846,8 @@ class NoteBook(EventGroup):
sortByDefault = "date"

def getSortByValue(self, event: "Event", attr: str) -> "Any":
if event.name in self.acceptsEventTypes:
if attr == "date":
return event.getJd()
if event.name in self.acceptsEventTypes and attr == "date":
return event.getJd()
return EventGroup.getSortByValue(self, event, attr)


Expand Down Expand Up @@ -5248,12 +5244,14 @@ def getInfo(self) -> str:

def calcOccurrence(self, startJd: int, endJd: int) -> OccurSet:
epoch = self.epoch
if epoch is not None:
if self.getEpochFromJd(startJd) <= epoch < self.getEpochFromJd(endJd):
if not self.parent.showSeconds:
log.info("-------- showSeconds = False")
epoch -= epoch % 60
return TimeListOccurSet(epoch)
if (
epoch is not None and
self.getEpochFromJd(startJd) <= epoch < self.getEpochFromJd(endJd)
):
if not self.parent.showSeconds:
log.info("-------- showSeconds = False")
epoch -= epoch % 60
return TimeListOccurSet(epoch)
return TimeListOccurSet()


Expand Down Expand Up @@ -5596,9 +5594,8 @@ def getInfo(self) -> str:

def calcOccurrence(self, startJd: int, endJd: int) -> OccurSet:
jd = self.jd
if jd is not None:
if startJd <= jd < endJd:
return JdOccurSet({jd})
if jd is not None and startJd <= jd < endJd:
return JdOccurSet({jd})
return JdOccurSet()


Expand Down
2 changes: 1 addition & 1 deletion scal3/event_update_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def put(self, action, obj, sender):
raise TypeError(
f"invalid obj type {obj.__class__.__name__} for {action=}",
)
elif action == "eg":
elif action == "eg": # noqa: SIM102
if not isinstance(obj, event_lib.EventGroup):
raise TypeError(
f"invalid obj type {obj.__class__.__name__} for {action=}",
Expand Down
13 changes: 6 additions & 7 deletions scal3/locale_man.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def numEncode(
localeMode = "en"
if localeMode is None:
localeMode = langSh
elif isinstance(localeMode, int):
elif isinstance(localeMode, int): # noqa: SIM102
if langSh != "en":
module, ok = calTypes[localeMode]
if not ok:
Expand Down Expand Up @@ -443,7 +443,7 @@ def textNumEncode(
localeMode = "en"
if localeMode is None:
localeMode = langSh
elif isinstance(localeMode, int):
elif isinstance(localeMode, int): # noqa: SIM102
if langSh != "en":
module, ok = calTypes[localeMode]
if not ok:
Expand All @@ -465,7 +465,7 @@ def textNumEncode(
elif c in (",", "_"):
if changeSpecialChars:
c = tr(c)
elif c == "%":
elif c == "%": # noqa: SIM102
if changeSpecialChars:
c = tr(c, ctx="number formatting")
res += c
Expand Down Expand Up @@ -547,10 +547,9 @@ def dateLocale(year: int, month: int, day: int) -> str:
def cutText(text: str, n: int) -> str:
text = toStr(text)
newText = text[:n]
if len(text) > n:
if text[n] not in list(string.printable) + [ZWNJ]:
with suppress(UnicodeDecodeError):
newText += ZWJ
if len(text) > n and text[n] not in list(string.printable) + [ZWNJ]:
with suppress(UnicodeDecodeError):
newText += ZWJ
return newText


Expand Down
2 changes: 1 addition & 1 deletion scal3/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
scalDir = cwd + scalDir[1:]
elif scalDir[0] != "/":
scalDir = join(cwd, scalDir)
elif os.sep == "\\":
elif os.sep == "\\": # noqa: SIM102
if scalDir.startswith(".\\"):
scalDir = cwd + scalDir[1:]

Expand Down
50 changes: 24 additions & 26 deletions scal3/plugin_man.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,32 +709,30 @@ def load(self):
self.md = None

def getText(self, y, m, d):
if self.ymd:
if (y, m, d) in self.ymd:
if self.show_date:
return (
_(d)
+ " "
+ getMonthName(self.calType, m)
+ " "
+ _(y)
+ ": "
+ self.ymd[(y, m, d)]
)
return self.ymd[(y, m, d)]
if self.md:
if (m, d) in self.md:
if self.show_date:
return (
_(d)
+ " "
+ getMonthName(self.calType, m)
+ " "
+ _(y)
+ ": "
+ self.ymd[(y, m, d)]
)
return self.md[(m, d)]
if self.ymd and (y, m, d) in self.ymd:
if self.show_date:
return (
_(d)
+ " "
+ getMonthName(self.calType, m)
+ " "
+ _(y)
+ ": "
+ self.ymd[(y, m, d)]
)
return self.ymd[(y, m, d)]
if self.md and (m, d) in self.md:
if self.show_date:
return (
_(d)
+ " "
+ getMonthName(self.calType, m)
+ " "
+ _(y)
+ ": "
+ self.ymd[(y, m, d)]
)
return self.md[(m, d)]
return ""

def open_configure(self):
Expand Down
23 changes: 11 additions & 12 deletions scal3/s_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,17 @@ def getPath(self):


def makeOrderedData(data: "dict | list", params):
if isinstance(data, dict):
if params:
data = list(data.items())

def paramIndex(key):
try:
return params.index(key)
except ValueError:
return len(params)

data.sort(key=lambda x: paramIndex(x[0]))
data = OrderedDict(data)
if isinstance(data, dict) and params:
data = list(data.items())

def paramIndex(key):
try:
return params.index(key)
except ValueError:
return len(params)

data.sort(key=lambda x: paramIndex(x[0]))
data = OrderedDict(data)

return data

Expand Down
5 changes: 2 additions & 3 deletions scal3/ui_gtk/cal_type_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ def __init__(
if sgroupLabel is None:
sgroupLabel = gtk.SizeGroup(mode=gtk.SizeGroupMode.HORIZONTAL)
####
if not enableTitleLabel:
if hasEnable:
enableTitleLabel = _("Enable")
if not enableTitleLabel and hasEnable:
enableTitleLabel = _("Enable")
if hasEnable:
self.enableCheck = gtk.CheckButton(label=enableTitleLabel)
###
Expand Down
5 changes: 2 additions & 3 deletions scal3/ui_gtk/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ def updateVars(self) -> None:
def onKeyPress(self, arg: gtk.Widget, gevent: gdk.EventKey):
kname = gdk.keyval_name(gevent.keyval).lower()
for item in self.items:
if item.enable and kname in item.myKeys:
if item.onKeyPress(arg, gevent):
break
if item.enable and kname in item.myKeys and item.onKeyPress(arg, gevent):
break

def getOptionsWidget(self) -> gtk.Widget:
return None
Expand Down
8 changes: 5 additions & 3 deletions scal3/ui_gtk/day_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,11 @@ def drawWithContext(self, cr: "cairo.Context", _cursor: bool):
abbreviate=self.getWeekdayAbbreviate(),
relative=False,
)
if langHasUppercase and self.weekdayUppercaseParam:
if getattr(ui, self.weekdayUppercaseParam):
text = text.upper()
if langHasUppercase and self.weekdayUppercaseParam and getattr(
ui,
self.weekdayUppercaseParam,
):
text = text.upper()
daynum = newTextLayout(
self,
text,
Expand Down
Loading

0 comments on commit 47c9e8e

Please sign in to comment.