Skip to content

Commit 7b5c2bf

Browse files
committed
fix!: Fix shadowing of python builtins
conftest.py:87:5: A001 Variable `dir` is shadowing a Python builtin docs/conf.py:56:1: A001 Variable `copyright` is shadowing a Python builtin src/vcspull/_internal/config_reader.py:29:15: A002 Argument `format` is shadowing a Python builtin src/vcspull/_internal/config_reader.py:53:19: A002 Argument `format` is shadowing a Python builtin src/vcspull/_internal/config_reader.py:109:13: A001 Variable `format` is shadowing a Python builtin src/vcspull/_internal/config_reader.py:111:13: A001 Variable `format` is shadowing a Python builtin src/vcspull/_internal/config_reader.py:163:9: A002 Argument `format` is shadowing a Python builtin src/vcspull/_internal/config_reader.py:192:20: A002 Argument `format` is shadowing a Python builtin tests/helpers.py:54:25: A002 Argument `format` is shadowing a Python builtin Found 9 errors.
1 parent f0f3f61 commit 7b5c2bf

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

Diff for: conftest.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def set_xdg_config_path(
8484
@pytest.fixture(scope="function")
8585
def repos_path(user_path: pathlib.Path, request: pytest.FixtureRequest) -> pathlib.Path:
8686
"""Return temporary directory for repository checkout guaranteed unique."""
87-
dir = user_path / "repos"
88-
dir.mkdir(exist_ok=True)
87+
path = user_path / "repos"
88+
path.mkdir(exist_ok=True)
8989

9090
def clean() -> None:
91-
shutil.rmtree(dir)
91+
shutil.rmtree(path)
9292

9393
request.addfinalizer(clean)
94-
return dir
94+
return path

Diff for: docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
master_doc = "index"
5454

5555
project = about["__title__"]
56-
copyright = about["__copyright__"]
56+
project_copyright = about["__copyright__"]
5757

5858
version = "%s" % (".".join(about["__version__"].split("."))[:2])
5959
release = "%s" % (about["__version__"])

Diff for: src/vcspull/_internal/config_reader.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, content: "RawConfigData") -> None:
2626
self.content = content
2727

2828
@staticmethod
29-
def _load(format: "FormatLiteral", content: str) -> dict[str, t.Any]:
29+
def _load(fmt: "FormatLiteral", content: str) -> dict[str, t.Any]:
3030
"""Load raw config data and directly return it.
3131
3232
>>> ConfigReader._load("json", '{ "session_name": "my session" }')
@@ -35,22 +35,22 @@ def _load(format: "FormatLiteral", content: str) -> dict[str, t.Any]:
3535
>>> ConfigReader._load("yaml", 'session_name: my session')
3636
{'session_name': 'my session'}
3737
"""
38-
if format == "yaml":
38+
if fmt == "yaml":
3939
return t.cast(
4040
dict[str, t.Any],
4141
yaml.load(
4242
content,
4343
Loader=yaml.SafeLoader,
4444
),
4545
)
46-
elif format == "json":
46+
elif fmt == "json":
4747
return t.cast(dict[str, t.Any], json.loads(content))
4848
else:
49-
msg = f"{format} not supported in configuration"
49+
msg = f"{fmt} not supported in configuration"
5050
raise NotImplementedError(msg)
5151

5252
@classmethod
53-
def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader":
53+
def load(cls, fmt: "FormatLiteral", content: str) -> "ConfigReader":
5454
"""Load raw config data into a ConfigReader instance (to dump later).
5555
5656
>>> cfg = ConfigReader.load("json", '{ "session_name": "my session" }')
@@ -67,7 +67,7 @@ def load(cls, format: "FormatLiteral", content: str) -> "ConfigReader":
6767
"""
6868
return cls(
6969
content=cls._load(
70-
format=format,
70+
fmt=fmt,
7171
content=content,
7272
),
7373
)
@@ -106,15 +106,15 @@ def _from_file(cls, path: pathlib.Path) -> dict[str, t.Any]:
106106
content = path.open().read()
107107

108108
if path.suffix in [".yaml", ".yml"]:
109-
format: "FormatLiteral" = "yaml"
109+
fmt: "FormatLiteral" = "yaml"
110110
elif path.suffix == ".json":
111-
format = "json"
111+
fmt = "json"
112112
else:
113113
msg = f"{path.suffix} not supported in {path}"
114114
raise NotImplementedError(msg)
115115

116116
return cls._load(
117-
format=format,
117+
fmt=fmt,
118118
content=content,
119119
)
120120

@@ -160,7 +160,7 @@ def from_file(cls, path: pathlib.Path) -> "ConfigReader":
160160

161161
@staticmethod
162162
def _dump(
163-
format: "FormatLiteral",
163+
fmt: "FormatLiteral",
164164
content: "RawConfigData",
165165
indent: int = 2,
166166
**kwargs: t.Any,
@@ -173,23 +173,23 @@ def _dump(
173173
>>> ConfigReader._dump("json", { "session_name": "my session" })
174174
'{\n "session_name": "my session"\n}'
175175
"""
176-
if format == "yaml":
176+
if fmt == "yaml":
177177
return yaml.dump(
178178
content,
179179
indent=2,
180180
default_flow_style=False,
181181
Dumper=yaml.SafeDumper,
182182
)
183-
elif format == "json":
183+
elif fmt == "json":
184184
return json.dumps(
185185
content,
186186
indent=2,
187187
)
188188
else:
189-
msg = f"{format} not supported in config"
189+
msg = f"{fmt} not supported in config"
190190
raise NotImplementedError(msg)
191191

192-
def dump(self, format: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str:
192+
def dump(self, fmt: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str:
193193
r"""Dump via ConfigReader instance.
194194
195195
>>> cfg = ConfigReader({ "session_name": "my session" })
@@ -199,7 +199,7 @@ def dump(self, format: "FormatLiteral", indent: int = 2, **kwargs: t.Any) -> str
199199
'{\n "session_name": "my session"\n}'
200200
"""
201201
return self._dump(
202-
format=format,
202+
fmt=fmt,
203203
content=self.content,
204204
indent=indent,
205205
**kwargs,

Diff for: tests/helpers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ def write_config(config_path: pathlib.Path, content: str) -> pathlib.Path:
5151
return config_path
5252

5353

54-
def load_raw(data: str, format: t.Literal["yaml", "json"]) -> dict[str, t.Any]:
54+
def load_raw(data: str, fmt: t.Literal["yaml", "json"]) -> dict[str, t.Any]:
5555
"""Load configuration data via string value. Accepts yaml or json."""
56-
return ConfigReader._load(format=format, content=data)
56+
return ConfigReader._load(fmt=fmt, content=data)

Diff for: tests/test_config_file.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def json_config(config_path: pathlib.Path) -> pathlib.Path:
3131

3232

3333
def test_dict_equals_yaml() -> None:
34-
"""Verify that example YAML is returning expected dict format."""
34+
"""Verify that example YAML is returning expected dict fmt."""
3535
config = ConfigReader._load(
36-
format="yaml",
36+
fmt="yaml",
3737
content="""\
3838
/home/me/myproject/study/:
3939
linux: git+git://git.kernel.org/linux/torvalds/linux.git
@@ -142,7 +142,7 @@ def test_expandenv_and_homevars() -> None:
142142
.tmux:
143143
url: git+file://{git_repo_path}
144144
""",
145-
format="yaml",
145+
fmt="yaml",
146146
)
147147
config2 = load_raw(
148148
"""\
@@ -162,7 +162,7 @@ def test_expandenv_and_homevars() -> None:
162162
}
163163
}
164164
""",
165-
format="json",
165+
fmt="json",
166166
)
167167

168168
assert is_valid_config(config1)

Diff for: tests/test_sync.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_makes_recursive(
2525
) -> None:
2626
"""Ensure that syncing creates directories recursively."""
2727
conf = ConfigReader._load(
28-
format="yaml",
28+
fmt="yaml",
2929
content=textwrap.dedent(
3030
f"""
3131
{tmp_path}/study/myrepo:

0 commit comments

Comments
 (0)