Skip to content

Commit

Permalink
Changes made by ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
elParaguayo committed Oct 20, 2024
1 parent 01e432b commit c65b282
Show file tree
Hide file tree
Showing 55 changed files with 201 additions and 217 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ def linkcode_resolve(domain, info):
filename = info["module"].replace(".", "/")
if filename.endswith("widget"):
filename += f"/{widgets[info['fullname']]}"
return "https://github.com/elparaguayo/qtile-extras/tree/main/%s.py" % filename
return f"https://github.com/elparaguayo/qtile-extras/tree/main/{filename}.py"
10 changes: 4 additions & 6 deletions docs/sphinx_qtile_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def run(self):
node.document = self.state.document
result = ViewList()
for line in self.make_rst():
result.append(line, "<{0}>".format(self.__class__.__name__))
result.append(line, f"<{self.__class__.__name__}>")
nested_parse_with_titles(self.state, result, node)
return node.children

Expand Down Expand Up @@ -258,7 +258,7 @@ def make_rst(self):
if is_widget:
index = Path(__file__).parent / "_static" / "screenshots" / "widgets" / "shots.json"
try:
with open(index, "r") as f:
with open(index) as f:
shots = json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
shots = {}
Expand Down Expand Up @@ -304,8 +304,7 @@ def make_rst(self):
]

rst = qtile_class_template.render(**context)
for line in rst.splitlines():
yield line
yield from rst.splitlines()


class QtileModule(SimpleDirectiveMixin, Directive):
Expand Down Expand Up @@ -412,8 +411,7 @@ def make_rst(self):
obj = import_class(module, class_name)
for method in sorted(obj.hooks):
rst = qtile_hooks_template.render(method=method)
for line in rst.splitlines():
yield line
yield from rst.splitlines()


def generate_widget_screenshots():
Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, *args, drawer: Drawer | None = None, **kwargs):
def attach_drawer(self, drawer: Drawer):
self.drawer = drawer

def draw(self, x=0, y=0, colour: "ColorsType" = "FFFFFF"):
def draw(self, x=0, y=0, colour: ColorsType = "FFFFFF"):
if self.drawer is None:
logger.error("Cannot draw masked image. Did you forget to attach the drawer?")
return
Expand Down
8 changes: 4 additions & 4 deletions qtile_extras/layout/decorations/borders.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def __init__(self, **config):
_BorderStyle.__init__(self, **config)
self.add_defaults(GradientBorder.defaults)

if not isinstance(self.colours, (list, tuple)):
if not isinstance(self.colours, list | tuple):
raise ConfigError("colours must be a list or tuple.")

if self.offsets is None:
Expand Down Expand Up @@ -261,7 +261,7 @@ def __init__(self, **config):
self.add_defaults(GradientFrame.defaults)
self.offsets = [x / (len(self.colours) - 1) for x in range(len(self.colours))]

if not isinstance(self.colours, (list, tuple)):
if not isinstance(self.colours, list | tuple):
raise ConfigError("colours must be a list or tuple.")

self._check_colours()
Expand Down Expand Up @@ -408,7 +408,7 @@ def __init__(self, **config):
_BorderStyle.__init__(self, **config)
self.add_defaults(SolidEdge.defaults)

if not (isinstance(self.colours, (list, tuple)) and len(self.colours) == 4):
if not (isinstance(self.colours, list | tuple) and len(self.colours) == 4):
raise ConfigError("colours must have 4 values.")

self._check_colours()
Expand Down Expand Up @@ -488,7 +488,7 @@ def compare(self, win):
return self.fallback

for match, colour in self.matches:
if isinstance(match, (list, str)):
if isinstance(match, list | str):
matched = any(m.compare(win) for m in match)
else:
matched = match.compare(win)
Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/popup/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def from_dbus_menu(cls, qtile, dbusmenuitems, **config):
has_submenu=dbmitem.children_display == "submenu",
enabled=dbmitem.enabled,
**callbacks,
**config
**config,
)
)
prev_sep = sep
Expand Down
3 changes: 1 addition & 2 deletions qtile_extras/popup/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ def _place_control(self, control):
Layous therefore need to override this method with the specific rules
for that layout.
"""
pass

def draw(self):
"""
Expand Down Expand Up @@ -957,7 +956,7 @@ def mouse_in_control(self, x, y):
)

def button_press(self, x, y, button):
name = "Button{0}".format(button)
name = f"Button{button}"
if name in self.mouse_callbacks:
cmd = self.mouse_callbacks[name]
if isinstance(cmd, LazyCall):
Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/resources/dbusmenu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from qtile_extras.resources.dbusmenu.dbusmenu import DBUS_MENU_SPEC

if TYPE_CHECKING:
from typing import Callable
from collections.abc import Callable


MENU_INTERFACE = "com.canonical.dbusmenu"
Expand Down
71 changes: 34 additions & 37 deletions qtile_extras/resources/footballscores/footballmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __init__(
detailed - Do we want additional data (e.g. goal scorers, bookings)?
"""
super(FootballMatch, self).__init__()
super().__init__()
self.detailed = detailed
self.myteam = team
self.match = MatchDict()
Expand Down Expand Up @@ -144,7 +144,7 @@ def __bool__(self):
return self.__nonzero__()

def __repr__(self):
return "<FootballMatch('%s')>" % (self.myteam)
return f"<FootballMatch('{self.myteam}')>"

def __eq__(self, other):
if isinstance(other, self.__class__):
Expand Down Expand Up @@ -281,7 +281,7 @@ def _find_team_page(self):
teampage = "https://www.bbc.co.uk/sport/football/teams/" + team
validteam = self.check_page(teampage)
if validteam:
self.myteampage = "team/{}".format(team)
self.myteampage = f"team/{team}"
return True
else:
return False
Expand Down Expand Up @@ -318,9 +318,7 @@ def _find_match(self, payload):
match = payload["matchData"]

if match:
return list(match[0]["tournamentDatesWithEvents"].values())[0][0]["events"][
0
] # noqa: E501
return list(match[0]["tournamentDatesWithEvents"].values())[0][0]["events"][0] # noqa: E501
else:
return None

Expand Down Expand Up @@ -497,13 +495,13 @@ def _format_events(self, events):
times = []

if event[0].is_goal and event[0].is_own_goal:
name = "{} (OG)".format(name)
name = f"{name} (OG)"

for item in event:
dt = item.display_time

if item.is_goal and item.is_penalty:
dt = "{} pen".format(dt)
dt = f"{dt} pen"

times.append(dt)

Expand Down Expand Up @@ -634,33 +632,33 @@ def on_new_match(self, func):
self._on_new_match = func

@property
@_no_match(str())
@_no_match("")
def home_team(self):
"""Returns string of the home team's name"""
return self.match.homeTeam.name.full

@property
@_no_match(str())
@_no_match("")
def away_team(self):
"""Returns string of the away team's name"""
return self.match.awayTeam.name.full

@property
@_no_match(int())
@_no_match(0)
@_override_none(0)
def home_score(self):
"""Returns the number of goals scored by the home team"""
return self.match.homeTeam.scores.score

@property
@_no_match(int())
@_no_match(0)
@_override_none(0)
def away_score(self):
"""Returns the number of goals scored by the away team"""
return self.match.awayTeam.scores.score

@property
@_no_match(str())
@_no_match("")
def competition(self):
"""Returns the name of the competition to which the match belongs
Expand All @@ -670,7 +668,7 @@ def competition(self):
return self.match.tournamentName.full

@property
@_no_match(str())
@_no_match("")
def status(self):
"""Returns the status of the match
Expand All @@ -680,17 +678,17 @@ def status(self):
return self.match.eventProgress.period

@property
@_no_match(str())
@_no_match("")
def long_status(self):
return self.match.eventStatusNote

@property
@_no_match(str())
@_no_match("")
def display_time(self):
me = self.elapsed_time
et = self.added_time

miat = "+{}".format(et) if et else ""
miat = f"+{et}" if et else ""

if self.is_postponed:
return "P"
Expand All @@ -705,25 +703,25 @@ def display_time(self):
return self.start_time_uk

elif me is not None:
return "{}{}'".format(me, miat)
return f"{me}{miat}'"

else:
return None

@property
@_no_match(int())
@_no_match(0)
@_override_none(0)
def elapsed_time(self):
return self.match.minutesElapsed

@property
@_no_match(int())
@_no_match(0)
@_override_none(0)
def added_time(self):
return self.match.minutesIntoAddedTime

@property
@_no_match(str())
@_no_match("")
def venue(self):
return self.match.venue.name.full

Expand Down Expand Up @@ -764,7 +762,7 @@ def home_scorers(self):
return self._get_goals(self.match.homeTeam)

@property
@_no_match(str())
@_no_match("")
def home_scorer_text(self):
return self._format_events(self.home_scorers)

Expand All @@ -775,22 +773,22 @@ def away_scorers(self):
return self._get_goals(self.match.awayTeam)

@property
@_no_match(str())
@_no_match("")
def away_scorer_text(self):
return self._format_events(self.away_scorers)

@property
@_no_match(str())
@_no_match("")
def last_goal(self):
return self._last_event(self.ACTION_GOAL)

@property
@_no_match(str())
@_no_match("")
def last_home_goal(self):
return self._last_event(self.ACTION_GOAL, just_home=True)

@property
@_no_match(str())
@_no_match("")
def last_away_goal(self):
return self._last_event(self.ACTION_GOAL, just_away=True)

Expand All @@ -807,17 +805,17 @@ def away_red_cards(self):
return self._get_reds(self.match.awayTeam)

@property
@_no_match(str())
@_no_match("")
def last_home_red_card(self):
return self._last_reds(just_home=True)

@property
@_no_match(str())
@_no_match("")
def last_away_red_card(self):
return self._last_reds(just_away=True)

@property
@_no_match(str())
@_no_match("")
def last_red_card(self):
return self._last_reds()

Expand All @@ -830,16 +828,15 @@ def __unicode__(self):
"""
if self.match:
return "%s %s-%s %s (%s)" % (
self.home_team,
self.home_score,
self.away_score,
self.away_team,
self.display_time,
return (
f"{self.home_team} "
f"{self.home_score}-{self.away_score} "
f"{self.away_team} "
f"({self.display_time})"
)

else:
return "%s are not playing today." % (self.myteam)
return f"{self.myteam} are not playing today."

def __str__(self):
"""Returns short formatted summary of match.
Expand All @@ -850,7 +847,7 @@ def __str__(self):
return self.__unicode__()

@property
@_no_match(str())
@_no_match("")
def start_time_uk(self):
return self.match.startTimeInUKHHMM

Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/resources/footballscores/league.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
on_status_change=None,
on_new_match=None,
):
super(League, self).__init__()
super().__init__()
self.league = league
self.matches = []
self.detailed = detailed
Expand Down
4 changes: 2 additions & 2 deletions qtile_extras/resources/footballscores/matchdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
class MatchDictKeys(object):
class MatchDictKeys:
AWAY_TEAM = "awayTeam"
COMMENT = "comment"
CPS_ID = "cpsId"
Expand Down Expand Up @@ -73,7 +73,7 @@ def __setitem__(self, item, value):
if isinstance(value, dict):
value = MatchDict(value)

super(MatchDict, self).__setitem__(item, value)
super().__setitem__(item, value)

def add_callback(self, key, callback):
if key in self._callbacks:
Expand Down
Loading

0 comments on commit c65b282

Please sign in to comment.