Skip to content

Commit b7babe6

Browse files
Avoid shadowing builtins (#303)
1 parent 85e8cc3 commit b7babe6

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

pins/boards.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,16 @@ def _pin_store(
228228
*,
229229
force_identical_write: bool = False,
230230
) -> Meta:
231-
if type == "feather":
231+
_type = type
232+
if _type == "feather":
232233
warn_deprecated(
233234
'Writing pin type "feather" is unsupported. Switching type to "arrow".'
234235
" This produces the exact same behavior, and also works with R pins."
235236
' Please switch to pin_write using type="arrow".'
236237
)
237-
type = "arrow"
238+
_type = "arrow"
238239

239-
if type == "file":
240+
if _type == "file":
240241
# the file type makes the name of the data the exact filename, rather
241242
# than the pin name + a suffix (e.g. my_pin.csv).
242243
if isinstance(x, (tuple, list)) and len(x) == 1:
@@ -264,7 +265,7 @@ def _pin_store(
264265
tmp_dir,
265266
x,
266267
pin_name,
267-
type,
268+
_type,
268269
title,
269270
description,
270271
metadata,

pins/cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def __call__(self, path: str) -> str:
6868
if self.hash_prefix is not None:
6969
# optionally make the name relative to a parent path
7070
# using the hash of parent path as a prefix, to flatten a bit
71-
hash = Path(path).relative_to(Path(self.hash_prefix))
72-
return hash
71+
_hash = Path(path).relative_to(Path(self.hash_prefix))
72+
return _hash
7373

7474
else:
7575
raise NotImplementedError()
@@ -102,8 +102,8 @@ def __call__(self, path):
102102
# the main change in this function is that, for same_name, it returns
103103
# the full path
104104
# change pin path of form <user>/<content> to <user>+<content>
105-
hash = path.replace("/", "+", 1)
106-
return hash
105+
_hash = path.replace("/", "+", 1)
106+
return _hash
107107

108108

109109
class PinsCache(SimpleCacheFileSystem):

pins/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def warn_deprecated(msg):
2222

2323
def hash_name(path, same_name):
2424
if same_name:
25-
hash = os.path.basename(path)
25+
_hash = os.path.basename(path)
2626
else:
27-
hash = hashlib.sha256(path.encode()).hexdigest()
28-
return hash
27+
_hash = hashlib.sha256(path.encode()).hexdigest()
28+
return _hash
2929

3030

3131
class ExtendMethodDoc:

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ select = [
124124
"I", # Import sorting
125125
"UP", # Upgrade to latest supported Python syntax
126126
"W", # Style
127+
"A", # Don't shadow built-ins
127128
]
128129
ignore = [
129130
"E501", # Line too long
131+
"A002", # The pins interface includes builtin names in args, e.g. hash, id, etc.
130132
]

0 commit comments

Comments
 (0)