Skip to content

Commit

Permalink
fix!: Fix shadowing of python builtins
Browse files Browse the repository at this point in the history
docs/_ext/aafig.py:59:5: A001 Variable `id` is shadowing a Python builtin
docs/_ext/aafig.py:121:9: A001 Variable `format` is shadowing a Python builtin
docs/_ext/aafig.py:137:27: A001 Variable `id` is shadowing a Python builtin
docs/conf.py:59:1: A001 Variable `copyright` is shadowing a Python builtin
src/tmuxp/_internal/config_reader.py:30:15: A002 Argument `format` is shadowing a Python builtin
src/tmuxp/_internal/config_reader.py:54:19: A002 Argument `format` is shadowing a Python builtin
src/tmuxp/_internal/config_reader.py:110:13: A001 Variable `format` is shadowing a Python builtin
src/tmuxp/_internal/config_reader.py:112:13: A001 Variable `format` is shadowing a Python builtin
src/tmuxp/_internal/config_reader.py:164:9: A002 Argument `format` is shadowing a Python builtin
src/tmuxp/_internal/config_reader.py:193:20: A002 Argument `format` is shadowing a Python builtin
Found 10 errors.
  • Loading branch information
tony committed Feb 7, 2024
1 parent 566ed09 commit 265eb14
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 57 deletions.
14 changes: 7 additions & 7 deletions docs/_ext/aafig.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def get_basename(
if "format" in options:
del options["format"]
hashkey = text + str(options)
id = sha(hashkey.encode("utf-8")).hexdigest()
return f"{prefix}-{id}"
_id = sha(hashkey.encode("utf-8")).hexdigest()
return f"{prefix}-{_id}"


class AafigError(SphinxError):
Expand Down Expand Up @@ -118,23 +118,23 @@ def render_aafig_images(app: "Sphinx", doctree: nodes.Node) -> None:
continue
options = img.aafig["options"]
text = img.aafig["text"]
format = app.builder.format
_format = app.builder.format
merge_dict(options, app.builder.config.aafig_default_options)
if format in format_map:
options["format"] = format_map[format]
if _format in format_map:
options["format"] = format_map[_format]
else:
logger.warn(
'unsupported builder format "%s", please '
"add a custom entry in aafig_format config "
"option for this builder" % format,
"option for this builder" % _format,
)
img.replace_self(nodes.literal_block(text, text))
continue
if options["format"] is None:
img.replace_self(nodes.literal_block(text, text))
continue
try:
fname, outfn, id, extra = render_aafigure(app, text, options)
fname, outfn, _id, extra = render_aafigure(app, text, options)
except AafigError as exc:
logger.warn("aafigure error: " + str(exc))
img.replace_self(nodes.literal_block(text, text))
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
master_doc = "index"

project = about["__title__"]
copyright = about["__copyright__"]
project_copyright = about["__copyright__"]

version = "%s" % (".".join(about["__version__"].split("."))[:2])
release = "%s" % (about["__version__"])
Expand Down
30 changes: 15 additions & 15 deletions src/tmuxp/_internal/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, content: "RawConfigData") -> None:
self.content = content

@staticmethod
def _load(format: "FormatLiteral", content: str) -> t.Dict[str, t.Any]:
def _load(fmt: "FormatLiteral", content: str) -> t.Dict[str, t.Any]:
"""Load raw config data and directly return it.
>>> ConfigReader._load("json", '{ "session_name": "my session" }')
Expand All @@ -36,22 +36,22 @@ def _load(format: "FormatLiteral", content: str) -> t.Dict[str, t.Any]:
>>> ConfigReader._load("yaml", 'session_name: my session')
{'session_name': 'my session'}
"""
if format == "yaml":
if fmt == "yaml":
return t.cast(
t.Dict[str, t.Any],
yaml.load(
content,
Loader=yaml.SafeLoader,
),
)
elif format == "json":
elif fmt == "json":
return t.cast(t.Dict[str, t.Any], json.loads(content))
else:
msg = f"{format} not supported in configuration"
msg = f"{fmt} not supported in configuration"
raise NotImplementedError(msg)

@classmethod
def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader":
def load(cls, fmt: "FormatLiteral", content: str) -> "ConfigReader":
"""Load raw config data into a ConfigReader instance (to dump later).
>>> cfg = ConfigReader.load("json", '{ "session_name": "my session" }')
Expand All @@ -68,7 +68,7 @@ def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader":
"""
return cls(
content=cls._load(
format=format,
fmt=fmt,
content=content,
),
)
Expand Down Expand Up @@ -107,15 +107,15 @@ def _from_file(cls, path: pathlib.Path) -> t.Dict[str, t.Any]:
content = path.open().read()

if path.suffix in [".yaml", ".yml"]:
format: "FormatLiteral" = "yaml"
fmt: "FormatLiteral" = "yaml"
elif path.suffix == ".json":
format = "json"
fmt = "json"
else:
msg = f"{path.suffix} not supported in {path}"
raise NotImplementedError(msg)

return cls._load(
format=format,
fmt=fmt,
content=content,
)

Expand Down Expand Up @@ -161,7 +161,7 @@ def from_file(cls, path: pathlib.Path) -> "ConfigReader":

@staticmethod
def _dump(
format: "FormatLiteral",
fmt: "FormatLiteral",
content: "RawConfigData",
indent: int = 2,
**kwargs: t.Any,
Expand All @@ -174,23 +174,23 @@ def _dump(
>>> ConfigReader._dump("json", { "session_name": "my session" })
'{\n "session_name": "my session"\n}'
"""
if format == "yaml":
if fmt == "yaml":
return yaml.dump(
content,
indent=2,
default_flow_style=False,
Dumper=yaml.SafeDumper,
)
elif format == "json":
elif fmt == "json":
return json.dumps(
content,
indent=2,
)
else:
msg = f"{format} not supported in config"
msg = f"{fmt} not supported in config"
raise NotImplementedError(msg)

def dump(self, format: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str:
def dump(self, fmt: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str:
r"""Dump via ConfigReader instance.
>>> cfg = ConfigReader({ "session_name": "my session" })
Expand All @@ -200,7 +200,7 @@ def dump(self, format: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str
'{\n "session_name": "my session"\n}'
"""
return self._dump(
format=format,
fmt=fmt,
content=self.content,
indent=indent,
**kwargs,
Expand Down
2 changes: 1 addition & 1 deletion src/tmuxp/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def command_convert(
newfile = workspace_file.parent / (str(workspace_file.stem) + f".{to_filetype}")

new_workspace = configparser.dump(
format=to_filetype,
fmt=to_filetype,
indent=2,
**{"default_flow_style": False} if to_filetype == "yaml" else {},
)
Expand Down
4 changes: 2 additions & 2 deletions src/tmuxp/cli/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ def extract_workspace_format(

if workspace_format == "yaml":
workspace = configparser.dump(
format="yaml",
fmt="yaml",
indent=2,
default_flow_style=False,
safe=True,
)
elif workspace_format == "json":
workspace = configparser.dump(format="json", indent=2)
workspace = configparser.dump(fmt="json", indent=2)

if args.answer_yes or prompt_yes_no("Save to %s?" % dest):
destdir = os.path.dirname(dest)
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_reattach_plugins(
"""Test reattach plugin hook."""
config_plugins = test_utils.read_workspace_file("workspace/builder/plugin_r.yaml")

session_config = ConfigReader._load(format="yaml", content=config_plugins)
session_config = ConfigReader._load(fmt="yaml", content=config_plugins)
session_config = loader.expand(session_config)

# open it detached
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_freeze(
assert yaml_config_path.exists()

yaml_config = yaml_config_path.open().read()
frozen_config = ConfigReader._load(format="yaml", content=yaml_config)
frozen_config = ConfigReader._load(fmt="yaml", content=yaml_config)

assert frozen_config["session_name"] == "myfrozensession"

Expand Down
12 changes: 6 additions & 6 deletions tests/cli/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def test_load_plugins(

plugins_config = test_utils.read_workspace_file("workspace/builder/plugin_bwb.yaml")

session_config = ConfigReader._load(format="yaml", content=plugins_config)
session_config = ConfigReader._load(fmt="yaml", content=plugins_config)
session_config = loader.expand(session_config)

plugins = load_plugins(session_config)
Expand Down Expand Up @@ -582,7 +582,7 @@ def test_load_attached(
attach_session_mock.return_value.stderr = None

yaml_config = test_utils.read_workspace_file("workspace/builder/two_pane.yaml")
session_config = ConfigReader._load(format="yaml", content=yaml_config)
session_config = ConfigReader._load(fmt="yaml", content=yaml_config)

builder = WorkspaceBuilder(session_config=session_config, server=server)

Expand All @@ -604,7 +604,7 @@ def test_load_attached_detached(
attach_session_mock.return_value.stderr = None

yaml_config = test_utils.read_workspace_file("workspace/builder/two_pane.yaml")
session_config = ConfigReader._load(format="yaml", content=yaml_config)
session_config = ConfigReader._load(fmt="yaml", content=yaml_config)

builder = WorkspaceBuilder(session_config=session_config, server=server)

Expand All @@ -626,7 +626,7 @@ def test_load_attached_within_tmux(
switch_client_mock.return_value.stderr = None

yaml_config = test_utils.read_workspace_file("workspace/builder/two_pane.yaml")
session_config = ConfigReader._load(format="yaml", content=yaml_config)
session_config = ConfigReader._load(fmt="yaml", content=yaml_config)

builder = WorkspaceBuilder(session_config=session_config, server=server)

Expand All @@ -648,7 +648,7 @@ def test_load_attached_within_tmux_detached(
switch_client_mock.return_value.stderr = None

yaml_config = test_utils.read_workspace_file("workspace/builder/two_pane.yaml")
session_config = ConfigReader._load(format="yaml", content=yaml_config)
session_config = ConfigReader._load(fmt="yaml", content=yaml_config)

builder = WorkspaceBuilder(session_config=session_config, server=server)

Expand All @@ -663,7 +663,7 @@ def test_load_append_windows_to_current_session(
) -> None:
"""Test tmuxp load when windows are appended to the current session."""
yaml_config = test_utils.read_workspace_file("workspace/builder/two_pane.yaml")
session_config = ConfigReader._load(format="yaml", content=yaml_config)
session_config = ConfigReader._load(fmt="yaml", content=yaml_config)

builder = WorkspaceBuilder(session_config=session_config, server=server)
builder.build()
Expand Down
14 changes: 7 additions & 7 deletions tests/workspace/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def test_start_directory(session: Session, tmp_path: pathlib.Path) -> None:
)
test_config = yaml_workspace.format(TEST_DIR=test_dir)

workspace = ConfigReader._load(format="yaml", content=test_config)
workspace = ConfigReader._load(fmt="yaml", content=test_config)
workspace = loader.expand(workspace)
workspace = loader.trickle(workspace)

Expand Down Expand Up @@ -620,7 +620,7 @@ def test_start_directory_relative(session: Session, tmp_path: pathlib.Path) -> N
config_dir.mkdir()

test_config = yaml_workspace.format(TEST_DIR=test_dir)
workspace = ConfigReader._load(format="yaml", content=test_config)
workspace = ConfigReader._load(fmt="yaml", content=test_config)
# the second argument of os.getcwd() mimics the behavior
# the CLI loader will do, but it passes in the workspace file's location.
workspace = loader.expand(workspace, config_dir)
Expand Down Expand Up @@ -692,7 +692,7 @@ def test_pane_order(session: Session) -> None:
str(pathlib.Path().home().resolve()),
]

workspace = ConfigReader._load(format="yaml", content=yaml_workspace)
workspace = ConfigReader._load(fmt="yaml", content=yaml_workspace)
workspace = loader.expand(workspace)
workspace = loader.trickle(workspace)

Expand Down Expand Up @@ -761,7 +761,7 @@ def test_before_script_throw_error_if_retcode_error(
script_failed=FIXTURE_PATH / "script_failed.sh",
)

workspace = ConfigReader._load(format="yaml", content=yaml_workspace)
workspace = ConfigReader._load(fmt="yaml", content=yaml_workspace)
workspace = loader.expand(workspace)
workspace = loader.trickle(workspace)

Expand All @@ -788,7 +788,7 @@ def test_before_script_throw_error_if_file_not_exists(
yaml_workspace = config_script_not_exists.format(
script_not_exists=FIXTURE_PATH / "script_not_exists.sh",
)
workspace = ConfigReader._load(format="yaml", content=yaml_workspace)
workspace = ConfigReader._load(fmt="yaml", content=yaml_workspace)
workspace = loader.expand(workspace)
workspace = loader.trickle(workspace)

Expand Down Expand Up @@ -818,7 +818,7 @@ def test_before_script_true_if_test_passes(
assert script_complete_sh.exists()

yaml_workspace = config_script_completes.format(script_complete=script_complete_sh)
workspace = ConfigReader._load(format="yaml", content=yaml_workspace)
workspace = ConfigReader._load(fmt="yaml", content=yaml_workspace)
workspace = loader.expand(workspace)
workspace = loader.trickle(workspace)

Expand All @@ -840,7 +840,7 @@ def test_before_script_true_if_test_passes_with_args(

yaml_workspace = config_script_completes.format(script_complete=script_complete_sh)

workspace = ConfigReader._load(format="yaml", content=yaml_workspace)
workspace = ConfigReader._load(fmt="yaml", content=yaml_workspace)
workspace = loader.expand(workspace)
workspace = loader.trickle(workspace)

Expand Down
Loading

0 comments on commit 265eb14

Please sign in to comment.