Skip to content

Commit ea70321

Browse files
committed
sty: Add pyupgrade checks
1 parent 21d9b62 commit ea70321

File tree

9 files changed

+20
-23
lines changed

9 files changed

+20
-23
lines changed

tools/schemacode/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ select = [
144144
"Q", # flake8-quotes
145145
"YTT", # flake8-2020
146146
"ISC", # implicit-string-concatenation
147+
"UP", # pyupgrade
147148

148149
# Intend to evaluate these for inclusion
149150
# "PD", # pandas-vet

tools/schemacode/src/bidsschematools/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
22
import tempfile
3+
from collections.abc import Generator
34
from pathlib import Path
45
from subprocess import run
5-
from typing import Generator
66

77
import pytest
88

tools/schemacode/src/bidsschematools/render/tables.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
import typing as ty
6-
75
import pandas as pd
86
from tabulate import tabulate
97

@@ -133,8 +131,8 @@ def _make_object_table(
133131
def _make_table_from_rule(
134132
schema: Namespace,
135133
table_type: str,
136-
table_name: ty.Union[str, ty.List[str]],
137-
src_path: ty.Optional[str] = None,
134+
table_name: str | list[str],
135+
src_path: str | None = None,
138136
tablefmt: str = "github",
139137
):
140138
"""Create a table for one or more rules.
@@ -404,8 +402,8 @@ def preproc_suffix(row):
404402

405403
def make_json_table(
406404
schema: Namespace,
407-
table_name: ty.Union[str, ty.List[str]],
408-
src_path: ty.Optional[str] = None,
405+
table_name: str | list[str],
406+
src_path: str | None = None,
409407
tablefmt: str = "github",
410408
):
411409
"""Produce metadata table (markdown) based on requested fields.
@@ -440,8 +438,8 @@ def make_json_table(
440438

441439
def make_sidecar_table(
442440
schema: Namespace,
443-
table_name: ty.Union[str, ty.List[str]],
444-
src_path: ty.Optional[str] = None,
441+
table_name: str | list[str],
442+
src_path: str | None = None,
445443
tablefmt: str = "github",
446444
):
447445
"""Produce metadata table (markdown) based on requested fields.
@@ -539,7 +537,7 @@ def make_metadata_table(schema, field_info, src_path=None, tablefmt="github"):
539537
def make_subobject_table(
540538
schema: Namespace,
541539
object_name: str,
542-
src_path: ty.Optional[str] = None,
540+
src_path: str | None = None,
543541
tablefmt: str = "github",
544542
):
545543
"""Create a metadata table (markdown) based on the properties of an object
@@ -590,7 +588,7 @@ def make_subobject_table(
590588
def make_columns_table(
591589
schema: Namespace,
592590
table_name: str,
593-
src_path: ty.Optional[str] = None,
591+
src_path: str | None = None,
594592
tablefmt: str = "github",
595593
):
596594
"""Produce columns table (markdown) based on requested fields.

tools/schemacode/src/bidsschematools/render/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _make_entity_definition(entity, entity_info):
6060
"""Describe an entity."""
6161
entity_shorthand = entity_info["name"]
6262
text = ""
63-
text += "## {}".format(entity_shorthand)
63+
text += f"## {entity_shorthand}"
6464
text += "\n\n"
6565
text += f"**Full name**: {entity_info['display_name']}"
6666
text += "\n\n"

tools/schemacode/src/bidsschematools/rules.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import fnmatch
88
import re
9-
import typing as ty
109
from collections.abc import Mapping
1110
from functools import lru_cache
1211

@@ -64,7 +63,7 @@ def _optional_regex(regex, optional):
6463
return f"(?:{regex})?" if optional else regex
6564

6665

67-
@lru_cache()
66+
@lru_cache
6867
def _format_entity(entity, name, pattern, level, directory=False):
6968
if directory and entity not in DIR_ENTITIES:
7069
return ""
@@ -141,7 +140,7 @@ def _entity_rule(rule: Mapping, schema: bst.types.Namespace):
141140
}
142141

143142

144-
def _split_inheritance_rules(rule: dict) -> ty.List[dict]:
143+
def _split_inheritance_rules(rule: dict) -> list[dict]:
145144
"""Break composite rules into main and sidecar rules
146145
147146
Implements the inheritance principle for file naming.
@@ -237,7 +236,7 @@ def regexify_filename_rules(
237236
return regex_schema
238237

239238

240-
@lru_cache()
239+
@lru_cache
241240
def regexify_all(schema_dir=None):
242241
"""
243242
Create full path regexes for all BIDS specification files.

tools/schemacode/src/bidsschematools/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def flatten_enums(namespace, inplace=True):
175175
return namespace
176176

177177

178-
@lru_cache()
178+
@lru_cache
179179
def load_schema(schema_path=None):
180180
"""Load the schema into a dictionary.
181181

tools/schemacode/src/bidsschematools/tests/test_expressions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from collections.abc import Mapping
22
from functools import singledispatch
3-
from typing import Union
43

54
import pytest
65
from pyparsing.exceptions import ParseException
@@ -147,7 +146,7 @@ def test_test_valid_sidecar_field():
147146

148147

149148
@singledispatch
150-
def find_names(node: Union[ASTNode, str]):
149+
def find_names(node: ASTNode | str):
151150
# Walk AST nodes
152151
if isinstance(node, BinOp):
153152
yield from find_names(node.lh)

tools/schemacode/src/bidsschematools/types/namespace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import yaml
1414

1515

16-
def _expand_dots(entry: ty.Tuple[str, ty.Any]) -> ty.Tuple[str, ty.Any]:
16+
def _expand_dots(entry: tuple[str, ty.Any]) -> tuple[str, ty.Any]:
1717
# Helper function for expand
1818
key, val = entry
1919
if "." in key:
@@ -220,7 +220,7 @@ def __getattribute__(self, key):
220220
except KeyError:
221221
raise err
222222

223-
def _get_mapping(self, key: str) -> ty.Tuple[Mapping, str]:
223+
def _get_mapping(self, key: str) -> tuple[Mapping, str]:
224224
subkeys = key.split(".")
225225
mapping = self._properties
226226
for subkey in subkeys[:-1]:

tools/schemacode/src/bidsschematools/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_logger(name=None, level=None):
3636
logging.Logger
3737
logger object.
3838
"""
39-
logger = logging.getLogger("bidsschematools" + (".%s" % name if name else ""))
39+
logger = logging.getLogger("bidsschematools" + (f".{name}" if name else ""))
4040
# If explicitly instructed via env var -- set log level
4141
if log_level := os.getenv("BIDS_SCHEMA_LOG_LEVEL", level):
4242
set_logger_level(logger, log_level)
@@ -79,6 +79,6 @@ def set_logger_level(lgr, level):
7979
elif level.isalpha():
8080
level = getattr(logging, level)
8181
else:
82-
lgr.warning("Do not know how to treat loglevel %s" % level)
82+
lgr.warning("Do not know how to treat loglevel %s", level)
8383
return
8484
lgr.setLevel(level)

0 commit comments

Comments
 (0)