Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce ruff/tryceratops rule TRY300 #4450

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg_resources/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def load_module(self, fullname: str):
"""
root, base, target = fullname.partition(self.root_name + '.')
for prefix in self.search_path:
extant = prefix + target
try:
extant = prefix + target
__import__(extant)
mod = sys.modules[extant]
sys.modules[fullname] = mod
return mod
except ImportError:
pass
continue
mod = sys.modules[extant]
sys.modules[fullname] = mod
return mod
else:
raise ImportError(
"The '{target}' package is required; "
Expand Down
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ extend-select = [
"F404", # late-future-import
"PYI", # flake8-pyi
"UP", # pyupgrade
"TRY",
"YTT", # flake8-2020
]
ignore = [
"TRY301", # raise-within-try, it's handy
"UP015", # redundant-open-modes, explicit is preferred
"UP030", # temporarily disabled
"UP031", # temporarily disabled
Expand Down
2 changes: 1 addition & 1 deletion setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def _get_project_config_files(self, filenames=None):
"""Ignore ``pyproject.toml``, they are not related to setup_requires"""
try:
cfg, toml = super()._split_standard_project_metadata(filenames)
return cfg, ()
except Exception:
return filenames, ()
return cfg, ()

def finalize_options(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def _to_bytes(s):
def isascii(s):
try:
s.encode('ascii')
return True
except UnicodeError:
return False
return True


def _one_liner(text):
Expand Down
2 changes: 1 addition & 1 deletion setuptools/config/_validate_pyproject/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def pep508(value: str) -> bool:
"""
try:
_req.Requirement(value)
return True
except _req.InvalidRequirement:
return False
return True
DimitriPapadopoulos marked this conversation as resolved.
Show resolved Hide resolved

except ImportError: # pragma: no cover
_logger.warning(
Expand Down
6 changes: 3 additions & 3 deletions setuptools/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def get_version(self, paths=None, default="unknown"):
if self.attribute is None:
try:
f, p, i = find_module(self.module, paths)
if f:
f.close()
return default
except ImportError:
return None
if f:
f.close()
return default

v = get_module_constant(self.module, self.attribute, default, paths)

Expand Down
5 changes: 2 additions & 3 deletions setuptools/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ def _have_cython():
try:
# from (cython_impl) import build_ext
__import__(cython_impl, fromlist=['build_ext']).build_ext
return True
except Exception:
pass
return False
return False
return True


# for compatibility
Expand Down
10 changes: 5 additions & 5 deletions setuptools/extern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def load_module(self, fullname):
"""
root, base, target = fullname.partition(self.root_name + '.')
for prefix in self.search_path:
extant = prefix + target
try:
extant = prefix + target
__import__(extant)
mod = sys.modules[extant]
sys.modules[fullname] = mod
return mod
except ImportError:
pass
continue
mod = sys.modules[extant]
sys.modules[fullname] = mod
return mod
else:
raise ImportError(
"The '{target}' package is required; "
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def touch(path):
def symlink_or_skip_test(src, dst):
try:
os.symlink(src, dst)
return dst
except (OSError, NotImplementedError):
pytest.skip("symlink not supported in OS")
return dst
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. This is probably wrong! In the absence of a return statement, this used to return None in case of OSError/NotImplementedError.

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those were manual fixes as far as I can remember, not the result of --fix. I should have been clear about it.



class TestSdistTest:
Expand Down
Loading