From 0d49d39f1063b7e8528ea5cf632e68d20ad786d9 Mon Sep 17 00:00:00 2001 From: Mark Mayo Date: Tue, 20 Jun 2023 00:52:00 +1200 Subject: [PATCH] some python 3 language updates tidied imports converted some format strings to f-strings removed u-prefix for strings removed some unneeded brackets --- docs/conf.py | 18 +++++++++--------- schedule/__init__.py | 12 ++++++------ setup.py | 2 +- test_schedule.py | 19 ++++++++----------- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 083d3532..cd34e7e3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -57,18 +57,18 @@ master_doc = "index" # General information about the project. -project = u"schedule" -copyright = u'2020, Daniel Bader' -author = u'Daniel Bader' +project = "schedule" +copyright = '2020, Daniel Bader' +author = 'Daniel Bader' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u"1.2.0" +version = "1.2.0" # The full version, including alpha/beta/rc tags. -release = u"1.2.0" +release = "1.2.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -284,8 +284,8 @@ ( master_doc, "schedule.tex", - u"schedule Documentation", - u"Daniel Bader", + "schedule Documentation", + "Daniel Bader", "manual", ), ] @@ -327,7 +327,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, "schedule", u"schedule Documentation", [author], 1)] +man_pages = [(master_doc, "schedule", "schedule Documentation", [author], 1)] # If true, show URL addresses after external links. # @@ -343,7 +343,7 @@ ( master_doc, "schedule", - u"schedule Documentation", + "schedule Documentation", author, "schedule", "One line description of project.", diff --git a/schedule/__init__.py b/schedule/__init__.py index 2db9b0ad..2e587a16 100644 --- a/schedule/__init__.py +++ b/schedule/__init__.py @@ -37,14 +37,14 @@ [2] https://github.com/Rykian/clockwork [3] https://adam.herokuapp.com/past/2010/6/30/replace_cron_with_clockwork/ """ -from collections.abc import Hashable import datetime import functools import logging import random import re import time -from typing import Set, List, Optional, Callable, Union +from collections.abc import Hashable +from typing import Callable, List, Optional, Set, Union logger = logging.getLogger("schedule") @@ -295,7 +295,7 @@ def is_repr(j): if self.job_func is not None: args = [repr(x) if is_repr(x) else str(x) for x in self.job_func.args] - kwargs = ["%s=%s" % (k, repr(v)) for k, v in self.job_func.keywords.items()] + kwargs = [f"{k}={repr(v)}" for k, v in self.job_func.keywords.items()] call_repr = job_func_name + "(" + ", ".join(args + kwargs) + ")" else: call_repr = "[None]" @@ -545,7 +545,7 @@ def at(self, time_str: str, tz: Optional[str] = None): second = 0 if self.unit == "days" or self.start_day: hour = int(hour) - if not (0 <= hour <= 23): + if not 0 <= hour <= 23: raise ScheduleValueError( "Invalid number of hours ({} is not between 0 and 23)" ) @@ -710,7 +710,7 @@ def _schedule_next_run(self) -> None: ) if self.latest is not None: - if not (self.latest >= self.interval): + if not self.latest >= self.interval: raise ScheduleError("`latest` is greater than `interval`") interval = random.randint(self.interval, self.latest) else: @@ -732,7 +732,7 @@ def _schedule_next_run(self) -> None: ) if self.start_day not in weekdays: raise ScheduleValueError( - "Invalid start day (valid start days are {})".format(weekdays) + f"Invalid start day (valid start days are {weekdays})" ) weekday = weekdays.index(self.start_day) days_ahead = weekday - self.next_run.weekday() diff --git a/setup.py b/setup.py index a56d374a..50382c63 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ import codecs -from setuptools import setup +from setuptools import setup SCHEDULE_VERSION = "1.2.0" SCHEDULE_DOWNLOAD_URL = "https://github.com/dbader/schedule/tarball/" + SCHEDULE_VERSION diff --git a/test_schedule.py b/test_schedule.py index 7d4617ec..46694e58 100644 --- a/test_schedule.py +++ b/test_schedule.py @@ -1,23 +1,20 @@ """Unit tests for schedule.py""" import datetime import functools -import mock -import unittest import os import time +import unittest + +import mock + +import schedule +from schedule import (IntervalError, ScheduleError, ScheduleValueError, every, + repeat) # Silence "missing docstring", "method could be a function", # "class already defined", and "too many public methods" messages: -# pylint: disable-msg=R0201,C0111,E0102,R0904,R0901 +# pylint: disable-msg=C0111,E0102,R0904,R0901 -import schedule -from schedule import ( - every, - repeat, - ScheduleError, - ScheduleValueError, - IntervalError, -) # Set timezone to Europe/Berlin (CEST) to ensure global reproducibility os.environ["TZ"] = "CET-1CEST,M3.5.0,M10.5.0"