From 265eb14ca4e5993200a94e275eb710a8a6b61f11 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Wed, 7 Feb 2024 06:03:25 -0600 Subject: [PATCH] fix!: Fix shadowing of python builtins 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. --- docs/_ext/aafig.py | 14 +++++------ docs/conf.py | 2 +- src/tmuxp/_internal/config_reader.py | 30 +++++++++++------------ src/tmuxp/cli/convert.py | 2 +- src/tmuxp/cli/freeze.py | 4 +-- tests/cli/test_cli.py | 2 +- tests/cli/test_freeze.py | 2 +- tests/cli/test_load.py | 12 ++++----- tests/workspace/test_builder.py | 14 +++++------ tests/workspace/test_config.py | 20 +++++++-------- tests/workspace/test_freezer.py | 8 +++--- tests/workspace/test_import_teamocil.py | 2 +- tests/workspace/test_import_tmuxinator.py | 2 +- 13 files changed, 57 insertions(+), 57 deletions(-) diff --git a/docs/_ext/aafig.py b/docs/_ext/aafig.py index 02f874c59a..ad48660ef2 100644 --- a/docs/_ext/aafig.py +++ b/docs/_ext/aafig.py @@ -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): @@ -118,15 +118,15 @@ 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 @@ -134,7 +134,7 @@ def render_aafig_images(app: "Sphinx", doctree: nodes.Node) -> 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)) diff --git a/docs/conf.py b/docs/conf.py index 3ee1344183..25783a032f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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__"]) diff --git a/src/tmuxp/_internal/config_reader.py b/src/tmuxp/_internal/config_reader.py index 26be1f4dd6..0367537be8 100644 --- a/src/tmuxp/_internal/config_reader.py +++ b/src/tmuxp/_internal/config_reader.py @@ -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" }') @@ -36,7 +36,7 @@ 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( @@ -44,14 +44,14 @@ def _load(format: "FormatLiteral", content: str) -> t.Dict[str, t.Any]: 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" }') @@ -68,7 +68,7 @@ def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader": """ return cls( content=cls._load( - format=format, + fmt=fmt, content=content, ), ) @@ -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, ) @@ -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, @@ -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" }) @@ -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, diff --git a/src/tmuxp/cli/convert.py b/src/tmuxp/cli/convert.py index 3cd3bb5d90..5ff5c3606a 100644 --- a/src/tmuxp/cli/convert.py +++ b/src/tmuxp/cli/convert.py @@ -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 {}, ) diff --git a/src/tmuxp/cli/freeze.py b/src/tmuxp/cli/freeze.py index 056d9968b9..df1df52354 100644 --- a/src/tmuxp/cli/freeze.py +++ b/src/tmuxp/cli/freeze.py @@ -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) diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index 2370aecbd2..ac4ec3800d 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -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 diff --git a/tests/cli/test_freeze.py b/tests/cli/test_freeze.py index 0c4637b45a..687ab900aa 100644 --- a/tests/cli/test_freeze.py +++ b/tests/cli/test_freeze.py @@ -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" diff --git a/tests/cli/test_load.py b/tests/cli/test_load.py index ef6fa80d20..a0d77fdb5f 100644 --- a/tests/cli/test_load.py +++ b/tests/cli/test_load.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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() diff --git a/tests/workspace/test_builder.py b/tests/workspace/test_builder.py index 0adcce5d4c..17453d1200 100644 --- a/tests/workspace/test_builder.py +++ b/tests/workspace/test_builder.py @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tests/workspace/test_config.py b/tests/workspace/test_config.py index 3a4f461ac6..71e4f8e8c2 100644 --- a/tests/workspace/test_config.py +++ b/tests/workspace/test_config.py @@ -47,11 +47,11 @@ def test_workspace_expand1(config_fixture: "WorkspaceTestData") -> None: def test_workspace_expand2(config_fixture: "WorkspaceTestData") -> None: """Expand shell commands from string to list.""" unexpanded_dict = ConfigReader._load( - format="yaml", + fmt="yaml", content=config_fixture.expand2.unexpanded_yaml(), ) expanded_dict = ConfigReader._load( - format="yaml", + fmt="yaml", content=config_fixture.expand2.expanded_yaml(), ) assert loader.expand(unexpanded_dict) == expanded_dict @@ -141,7 +141,7 @@ def test_shell_command_before(config_fixture: "WorkspaceTestData") -> None: def test_in_session_scope(config_fixture: "WorkspaceTestData") -> None: """Verify shell_command before_session is in session scope.""" sconfig = ConfigReader._load( - format="yaml", + fmt="yaml", content=config_fixture.shell_command_before_session.before, ) @@ -149,7 +149,7 @@ def test_in_session_scope(config_fixture: "WorkspaceTestData") -> None: assert loader.expand(sconfig) == sconfig assert loader.expand(loader.trickle(sconfig)) == ConfigReader._load( - format="yaml", + fmt="yaml", content=config_fixture.shell_command_before_session.expected, ) @@ -171,7 +171,7 @@ def test_trickle_window_with_no_pane_workspace() -> None: - ls -l - window_name: test_no_panes """ - sconfig = ConfigReader._load(format="yaml", content=test_yaml) + sconfig = ConfigReader._load(fmt="yaml", content=test_yaml) validation.validate_schema(sconfig) assert loader.expand(loader.trickle(sconfig))["windows"][1]["panes"][0] == { @@ -226,7 +226,7 @@ def test_no_session_name() -> None: - htop """ - sconfig = ConfigReader._load(format="yaml", content=yaml_workspace) + sconfig = ConfigReader._load(fmt="yaml", content=yaml_workspace) with pytest.raises(exc.WorkspaceError) as excinfo: validation.validate_schema(sconfig) @@ -239,7 +239,7 @@ def test_no_windows() -> None: session_name: test session """ - sconfig = ConfigReader._load(format="yaml", content=yaml_workspace) + sconfig = ConfigReader._load(fmt="yaml", content=yaml_workspace) with pytest.raises(exc.WorkspaceError) as excinfo: validation.validate_schema(sconfig) @@ -262,7 +262,7 @@ def test_no_window_name() -> None: - htop """ - sconfig = ConfigReader._load(format="yaml", content=yaml_workspace) + sconfig = ConfigReader._load(fmt="yaml", content=yaml_workspace) with pytest.raises(exc.WorkspaceError) as excinfo: validation.validate_schema(sconfig) @@ -295,7 +295,7 @@ def test_replaces_env_variables(monkeypatch: pytest.MonkeyPatch) -> None: - htop """.format(TEST_VAR="${%s}" % env_key) - sconfig = ConfigReader._load(format="yaml", content=yaml_workspace) + sconfig = ConfigReader._load(fmt="yaml", content=yaml_workspace) monkeypatch.setenv(str(env_key), str(env_val)) sconfig = loader.expand(sconfig) @@ -324,7 +324,7 @@ def test_validate_plugins() -> None: start_directory: /var/log """ - sconfig = ConfigReader._load(format="yaml", content=yaml_workspace) + sconfig = ConfigReader._load(fmt="yaml", content=yaml_workspace) with pytest.raises(exc.WorkspaceError) as excinfo: validation.validate_schema(sconfig) diff --git a/tests/workspace/test_freezer.py b/tests/workspace/test_freezer.py index a91e6db770..9a1e897f5f 100644 --- a/tests/workspace/test_freezer.py +++ b/tests/workspace/test_freezer.py @@ -33,14 +33,14 @@ def test_freeze_config(session: Session) -> None: validation.validate_schema(new_config) # These should dump without an error - ConfigReader._dump(format="json", content=new_config) - ConfigReader._dump(format="yaml", content=new_config) + ConfigReader._dump(fmt="json", content=new_config) + ConfigReader._dump(fmt="yaml", content=new_config) # Inline configs should also dump without an error compact_config = freezer.inline(new_config) - ConfigReader._dump(format="json", content=compact_config) - ConfigReader._dump(format="yaml", content=compact_config) + ConfigReader._dump(fmt="json", content=compact_config) + ConfigReader._dump(fmt="yaml", content=compact_config) """Tests for :meth:`freezer.inline()`.""" diff --git a/tests/workspace/test_import_teamocil.py b/tests/workspace/test_import_teamocil.py index f2df8019ea..f945130bb4 100644 --- a/tests/workspace/test_import_teamocil.py +++ b/tests/workspace/test_import_teamocil.py @@ -41,7 +41,7 @@ def test_config_to_dict( ) -> None: """Test exporting teamocil configuration to dictionary.""" yaml_to_dict = config_reader.ConfigReader._load( - format="yaml", + fmt="yaml", content=teamocil_yaml, ) assert yaml_to_dict == teamocil_dict diff --git a/tests/workspace/test_import_tmuxinator.py b/tests/workspace/test_import_tmuxinator.py index 48a6e3761c..b7052fc167 100644 --- a/tests/workspace/test_import_tmuxinator.py +++ b/tests/workspace/test_import_tmuxinator.py @@ -35,7 +35,7 @@ def test_config_to_dict( tmuxp_dict: t.Dict[str, t.Any], ) -> None: """Test exporting tmuxinator configuration to dictionary.""" - yaml_to_dict = ConfigReader._load(format="yaml", content=tmuxinator_yaml) + yaml_to_dict = ConfigReader._load(fmt="yaml", content=tmuxinator_yaml) assert yaml_to_dict == tmuxinator_dict assert importers.import_tmuxinator(tmuxinator_dict) == tmuxp_dict