Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
ruff: Enable new lints DTZ, ISC, PIE, PLW, Q, S, SIM.
Anders Kaseorg2afdb460958c
diff --git a/pyproject.toml b/pyproject.tomlindex e38d8ec214f..0d2dc0bb34b 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -103,15 +103,22 @@ select = ["ANN", # annotations"B", # bugbear"C4", # comprehensions+ "DTZ", # naive datetime"E", # style errors"F", # flakes"I", # import sorting+ "ISC", # string concatenation"N", # naming"PGH", # pygrep-hooks+ "PIE", # miscellaneous"PLC", # pylint convention"PLE", # pylint error"PLR", # pylint refactor+ "PLW", # pylint warning+ "Q", # quotes"RUF", # Ruff+ "S", # security+ "SIM", # simplify"T10", # debugger"UP", # upgrade"W", # style warnings@@ -133,6 +140,10 @@ ignore = ["N806", # Variable in function should be lowercase"RUF001", # String contains ambiguous unicode character"RUF003", # Comment contains ambiguous unicode character+ "S101", # Use of `assert` detected+ "S105", # Possible hardcoded password+ "S106", # Possible hardcoded password+ "S107", # Possible hardcoded password]line-length = 100src = [".", "tools"]diff --git a/scripts/lib/setup_path.py b/scripts/lib/setup_path.pyindex 6062aeccce3..2861b19eee7 100644--- a/scripts/lib/setup_path.py+++ b/scripts/lib/setup_path.py@@ -12,7 +12,7 @@ def setup_path() -> None:activate_this = os.path.join(venv, "bin", "activate_this.py")activate_locals = dict(__file__=activate_this)with open(activate_this) as f:- exec(f.read(), activate_locals)+ exec(f.read(), activate_locals) # noqa: S102# Check that the python version running this function# is same as python version that created the virtualenv.python_version = "python{}.{}".format(*sys.version_info[:2])diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.pyindex 357e0d15c29..5a9f329e62c 100755--- a/scripts/lib/zulip_tools.py+++ b/scripts/lib/zulip_tools.py@@ -165,7 +165,7 @@ def su_to_zulip(save_suid: bool = False) -> None:def make_deploy_path() -> str:- timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT)+ timestamp = datetime.datetime.now().strftime(TIMESTAMP_FORMAT) # noqa: DTZ005return os.path.join(DEPLOYMENTS_DIR, timestamp)@@ -268,7 +268,9 @@ def get_recent_deployments(threshold_days: int) -> Set[str]:# Returns a list of deployments not older than threshold days# including `/root/zulip` directory if it exists.recent = set()- threshold_date = datetime.datetime.now() - datetime.timedelta(days=threshold_days)+ threshold_date = datetime.datetime.now() - datetime.timedelta( # noqa: DTZ005+ days=threshold_days+ )for dir_name in os.listdir(DEPLOYMENTS_DIR):target_dir = os.path.join(DEPLOYMENTS_DIR, dir_name)if not os.path.isdir(target_dir):@@ -278,7 +280,7 @@ def get_recent_deployments(threshold_days: int) -> Set[str]:# Skip things like "lock" that aren't actually a deployment directorycontinuetry:- date = datetime.datetime.strptime(dir_name, TIMESTAMP_FORMAT)+ date = datetime.datetime.strptime(dir_name, TIMESTAMP_FORMAT) # noqa: DTZ007if date >= threshold_date:recent.add(target_dir)except ValueError:@@ -295,7 +297,7 @@ def get_recent_deployments(threshold_days: int) -> Set[str]:def get_threshold_timestamp(threshold_days: int) -> int:# Given number of days, this function returns timestamp corresponding# to the time prior to given number of days.- threshold = datetime.datetime.now() - datetime.timedelta(days=threshold_days)+ threshold = datetime.datetime.now() - datetime.timedelta(days=threshold_days) # noqa: DTZ005threshold_timestamp = int(time.mktime(threshold.utctimetuple()))return threshold_timestampdiff --git a/tools/lib/provision.py b/tools/lib/provision.pyindex 8cb79565d9d..8f2c367001b 100755--- a/tools/lib/provision.py+++ b/tools/lib/provision.py@@ -461,7 +461,7 @@ def main(options: argparse.Namespace) -> NoReturn:activate_this = "/srv/zulip-py3-venv/bin/activate_this.py"provision_inner = os.path.join(ZULIP_PATH, "tools", "lib", "provision_inner.py")with open(activate_this) as f:- exec(f.read(), dict(__file__=activate_this))+ exec(f.read(), dict(__file__=activate_this)) # noqa: S102os.execvp(provision_inner,[diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.pyindex 52703840fcc..c905fdca2a1 100644--- a/tools/linter_lib/custom_check.py+++ b/tools/linter_lib/custom_check.py@@ -376,12 +376,6 @@ python_rules = RuleList(},"description": "Please use access_stream_by_*() to fetch Stream objects",},- {- "pattern": "datetime[.](now|utcnow)",- "include_only": {"zerver/", "analytics/"},- "description": "Don't use datetime in backend code.\n"- "See https://zulip.readthedocs.io/en/latest/contributing/code-style.html#naive-datetime-objects",- },{"pattern": "from os.path","description": "Don't use from when importing from the standard library",diff --git a/zerver/webhooks/taiga/view.py b/zerver/webhooks/taiga/view.pyindex 168779b73ac..193694587ff 100644--- a/zerver/webhooks/taiga/view.py+++ b/zerver/webhooks/taiga/view.py@@ -308,7 +308,7 @@ def parse_message(events.append(parse_create_or_delete(message))elif message["action"].tame(check_string) == "change":if message["change"]["diff"]:- for value in message["change"]["diff"].keys():+ for value in message["change"]["diff"].keys(): # noqa: SIM118parsed_event = parse_change_event(value, message)if parsed_event:events.append(parsed_event)