Skip to content

Commit

Permalink
Fix TC006 (quoting the type argument of cast())
Browse files Browse the repository at this point in the history
There is a long discussion in
<astral-sh/ruff#14676> about how useful this
rule is, especially the performance vs. syntax highlighting question.
Note that apparently `cast()` is not affected by `from __future__ import
annotations`; adding it won't help.

I'm kind of indifferent as to whether this is a good rule or not,
therefore I'll accept ruff's recommendation for now.

Signed-off-by: Tim Weber <[email protected]>
  • Loading branch information
scy committed Dec 9, 2024
1 parent 776cb3a commit 15ef6a8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/dearmep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def intervals_by_weekday(
If a weekday has no office hours, it will not be in the return value.
"""
return {
cast(WeekdayNumber, daynum): [
cast("WeekdayNumber", daynum): [
OfficeHoursInterval(begin=self.begin, end=self.end),
]
for daynum in range(1, 8)
Expand Down
4 changes: 2 additions & 2 deletions server/dearmep/convert/parltrack/mep.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ def convert_person(raw_mep: Dict[str, Any]) -> Iterable[DumpableModels]:
# Get the current group & constituency.
group = next((
group
for group in cast(List[Dict[str, str]], raw_mep.get("Groups", []))
for group in cast("List[Dict[str, str]]", raw_mep.get("Groups", []))
if is_current(group)
), None)
constituency = next((
constituency
for constituency in cast(
List[Dict[str, str]], raw_mep.get("Constituencies", []))
"List[Dict[str, str]]", raw_mep.get("Constituencies", []))
if is_current(constituency)
), None)

Expand Down
2 changes: 1 addition & 1 deletion server/dearmep/convert/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def get_text(node: Union[Element, Text]) -> str:
"""Recursively concatenate text nodes in the `node`."""
if node.nodeType == node.TEXT_NODE:
# This casting is plain ugly, but otherwise mypy doesn't know it's str.
return str(cast(Text, node).data)
return str(cast("Text", node).data)
return "".join(
get_text(child)
for child in node.childNodes
Expand Down
8 changes: 4 additions & 4 deletions server/dearmep/database/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def escape_for_like(value: str) -> str:

def get_available_countries(session: Session) -> List[str]:
countries = session.exec(select(Destination.country).distinct()).all()
return cast(List[str], countries) \
return cast("List[str]", countries) \
if isinstance(countries, List) and len(countries) \
and isinstance(countries[0], str) \
else []
Expand Down Expand Up @@ -800,11 +800,11 @@ def get_currently_scheduled_calls(
ScheduledCall.day == now.isoweekday(),
and_(
col(ScheduledCall.postponed_to).is_not(None),
cast(datetime, ScheduledCall.postponed_to) <= now,
cast("datetime", ScheduledCall.postponed_to) <= now,
),
or_(
col(ScheduledCall.last_postpone_queued_at).is_(None),
cast(date, ScheduledCall.last_postpone_queued_at) < now.date(),
cast("date", ScheduledCall.last_postpone_queued_at) < now.date(),
),
).order_by(ScheduledCall.postponed_to)).all()

Expand All @@ -817,7 +817,7 @@ def get_currently_scheduled_calls(
),
or_(
col(ScheduledCall.last_queued_at).is_(None),
cast(date, ScheduledCall.last_queued_at) < now.date(),
cast("date", ScheduledCall.last_queued_at) < now.date(),
),
).order_by(ScheduledCall.start_time)).all()

Expand Down

0 comments on commit 15ef6a8

Please sign in to comment.