From 6b399d7476f45365506efea3b4528c97003d47d4 Mon Sep 17 00:00:00 2001 From: Nathan McDougall Date: Wed, 21 Aug 2024 13:01:16 +1200 Subject: [PATCH] Avoid shadowing builtins --- pins/boards.py | 9 +++++---- pins/cache.py | 8 ++++---- pins/utils.py | 6 +++--- pyproject.toml | 2 ++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pins/boards.py b/pins/boards.py index 44e64ed..776ee81 100644 --- a/pins/boards.py +++ b/pins/boards.py @@ -226,15 +226,16 @@ def _pin_store( versioned: bool | None = None, created: datetime | None = None, ) -> Meta: - if type == "feather": + _type = type + if _type == "feather": warn_deprecated( 'Writing pin type "feather" is unsupported. Switching type to "arrow".' " This produces the exact same behavior, and also works with R pins." ' Please switch to pin_write using type="arrow".' ) - type = "arrow" + _type = "arrow" - if type == "file": + if _type == "file": # the file type makes the name of the data the exact filename, rather # than the pin name + a suffix (e.g. my_pin.csv). if isinstance(x, (tuple, list)) and len(x) == 1: @@ -254,7 +255,7 @@ def _pin_store( tmp_dir, x, pin_name, - type, + _type, title, description, metadata, diff --git a/pins/cache.py b/pins/cache.py index cadda23..fc511c6 100644 --- a/pins/cache.py +++ b/pins/cache.py @@ -65,8 +65,8 @@ def __call__(self, path: str) -> str: if self.hash_prefix is not None: # optionally make the name relative to a parent path # using the hash of parent path as a prefix, to flatten a bit - hash = Path(path).relative_to(Path(self.hash_prefix)) - return hash + _hash = Path(path).relative_to(Path(self.hash_prefix)) + return _hash else: raise NotImplementedError() @@ -99,8 +99,8 @@ def __call__(self, path): # the main change in this function is that, for same_name, it returns # the full path # change pin path of form / to + - hash = path.replace("/", "+", 1) - return hash + _hash = path.replace("/", "+", 1) + return _hash class PinsCache(SimpleCacheFileSystem): diff --git a/pins/utils.py b/pins/utils.py index a229dc2..7525c14 100644 --- a/pins/utils.py +++ b/pins/utils.py @@ -22,10 +22,10 @@ def warn_deprecated(msg): def hash_name(path, same_name): if same_name: - hash = os.path.basename(path) + _hash = os.path.basename(path) else: - hash = hashlib.sha256(path.encode()).hexdigest() - return hash + _hash = hashlib.sha256(path.encode()).hexdigest() + return _hash class ExtendMethodDoc: diff --git a/pyproject.toml b/pyproject.toml index f1f7af3..70ba52d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -127,7 +127,9 @@ select = [ "I", # Import sorting "UP", # Upgrade to latest supported Python syntax "W", # Style + "A", # Don't shadow built-ins ] ignore = [ "E501", # Line too long + "A002", # The pins interface includes builtin names in args, e.g. hash, id, etc. ]