Skip to content
New issue

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

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

Already on GitHub? # to your account

Enforce ruff/tryceratops rule TRY300 #4450

Merged
merged 1 commit into from
Jun 29, 2024
Merged

Conversation

DimitriPapadopoulos
Copy link
Contributor

Summary of changes

TRY300 Consider moving this statement to an `else` block

Pull Request Checklist

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the TRY branch 4 times, most recently from d1a07d0 to c7ad20b Compare June 29, 2024 12:54
TRY300 Consider moving this statement to an `else` block
@jaraco jaraco merged commit ad8c7ba into pypa:main Jun 29, 2024
20 of 22 checks passed
@DimitriPapadopoulos DimitriPapadopoulos deleted the TRY branch June 29, 2024 21:04
@Avasam
Copy link
Contributor

Avasam commented Jul 1, 2024

@DimitriPapadopoulos Have you tried running updated ruff on the codebase with this? I get 69 TRY003 Avoid specifying long messages outside the exception class https://docs.astral.sh/ruff/rules/raise-vanilla-args/ locally on 0.4.8 and 0.5.0 .
Personally I'd just ignore that specific check.

pkg_resources\__init__.py:28:11: TRY003 Avoid specifying long messages outside the exception class
   |
27 | if sys.version_info < (3, 8):  # noqa: UP036 # Check for unsupported versions
28 |     raise RuntimeError("Python 3.8 or later is required")
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
29 |
30 | import os
   |

pkg_resources\__init__.py:544:15: TRY003 Avoid specifying long messages outside the exception class
    |
542 |         dist = get_provider(dist)  # type: ignore[assignment]
543 |     if not isinstance(dist, Distribution):
544 |         raise TypeError("Expected str, Requirement, or Distribution", dist)
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
545 |     return dist
    |

pkg_resources\__init__.py:1508:19: TRY003 Avoid specifying long messages outside the exception class
     |
1506 |         """
1507 |         if self.cached_files:
1508 |             raise ValueError("Can't change extraction path, files already extracted")
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
1509 |
1510 |         self.extraction_path = path
     |

pkg_resources\__init__.py:1745:19: TRY003 Avoid specifying long messages outside the exception class
     |
1743 |       def _fn(self, base: str | None, resource_name: str):
1744 |           if base is None:
1745 |               raise TypeError(
     |  ___________________^
1746 | |                 "`base` parameter in `_fn` is `None`. Either override this method or check the parameter first."
1747 | |             )
     | |_____________^ TRY003
1748 |           self._validate_resource_path(resource_name)
1749 |           if resource_name:
     |

pkg_resources\__init__.py:2043:19: TRY003 Avoid specifying long messages outside the exception class
     |
2042 |           if not WRITE_SUPPORT:
2043 |               raise OSError(
     |  ___________________^
2044 | |                 '"os.rename" and "os.unlink" are not supported on this platform'
2045 | |             )
     | |_____________^ TRY003
2046 |           try:
2047 |               if not self.egg_name:
     |

pkg_resources\__init__.py:2048:23: TRY003 Avoid specifying long messages outside the exception class
     |
2046 |           try:
2047 |               if not self.egg_name:
2048 |                   raise OSError(
     |  _______________________^
2049 | |                     '"egg_name" is empty. This likely means no egg could be found from the "module_path".'
2050 | |                 )
     | |_________________^ TRY003
2051 |               real_path = manager.get_cache_path(self.egg_name, self._parts(zip_path))
     |

pkg_resources\__init__.py:2172:19: TRY003 Avoid specifying long messages outside the exception class
     |
2170 |     def get_metadata(self, name: str):
2171 |         if name != 'PKG-INFO':
2172 |             raise KeyError("No metadata except PKG-INFO is available")
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2173 |
2174 |         with open(self.path, encoding='utf-8', errors="replace") as f:
     |

pkg_resources\__init__.py:2463:15: TRY003 Avoid specifying long messages outside the exception class
     |
2461 |         _set_parent_ns(packageName)
2462 |     elif not hasattr(module, '__path__'):
2463 |         raise TypeError("Not a package:", packageName)
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2464 |     handler = _find_adapter(_namespace_handlers, importer)
2465 |     subpath = handler(importer, path_item, packageName, module)
     |

pkg_resources\__init__.py:2535:23: TRY003 Avoid specifying long messages outside the exception class
     |
2533 |                 path = sys.modules[parent].__path__
2534 |             except AttributeError as e:
2535 |                 raise TypeError("Not a package:", parent) from e
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2536 |
2537 |         # Track what packages are namespaces, so when new path items are added,
     |

pkg_resources\__init__.py:2694:19: TRY003 Avoid specifying long messages outside the exception class
     |
2692 |     ):
2693 |         if not MODULE(module_name):
2694 |             raise ValueError("Invalid module name", module_name)
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2695 |         self.name = name
2696 |         self.module_name = module_name
     |

pkg_resources\__init__.py:2765:19: TRY003 Avoid specifying long messages outside the exception class
     |
2763 |         if not self.dist:
2764 |             error_cls = UnknownExtra if self.extras else AttributeError
2765 |             raise error_cls("Can't require() without a distribution", self)
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2766 |
2767 |         # Get the requirements for this entry point with all its extras and
     |

pkg_resources\__init__.py:2823:19: TRY003 Avoid specifying long messages outside the exception class
     |
2821 |         """Parse an entry point group"""
2822 |         if not MODULE(group):
2823 |             raise ValueError("Invalid group name", group)
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2824 |         this: dict[str, Self] = {}
2825 |         for line in yield_lines(lines):
     |

pkg_resources\__init__.py:2828:23: TRY003 Avoid specifying long messages outside the exception class
     |
2826 |             ep = cls.parse(line, dist)
2827 |             if ep.name in this:
2828 |                 raise ValueError("Duplicate entry point", group, ep.name)
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2829 |             this[ep.name] = ep
2830 |         return this
     |

pkg_resources\__init__.py:2849:23: TRY003 Avoid specifying long messages outside the exception class
     |
2847 |                 if not lines:
2848 |                     continue
2849 |                 raise ValueError("Entry points must be listed in groups")
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2850 |             group = group.strip()
2851 |             if group in maps:
     |

pkg_resources\__init__.py:2852:23: TRY003 Avoid specifying long messages outside the exception class
     |
2850 |             group = group.strip()
2851 |             if group in maps:
2852 |                 raise ValueError("Duplicate group name", group)
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2853 |             maps[group] = cls.parse_group(group, lines, dist)
2854 |         return maps
     |

pkg_resources\__init__.py:2984:23: TRY003 Avoid specifying long messages outside the exception class
     |
2982 |                     ex.add_note(info)  # PEP 678
2983 |                     raise
2984 |                 raise _packaging_version.InvalidVersion(f"{str(ex)} {info}") from None
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2985 |
2986 |         return self._parsed_version
     |

pkg_resources\__init__.py:3499:11: TRY003 Avoid specifying long messages outside the exception class
     |
3497 |     # _find_adapter would previously return None, and immediately be called.
3498 |     # So we're raising a TypeError to keep backward compatibility if anyone depended on that behaviour.
3499 |     raise TypeError(f"Could not find adapter for {registry} and {ob}")
     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
     |

pkg_resources\__init__.py:3511:15: TRY003 Avoid specifying long messages outside the exception class
     |
3509 |     """Sandbox-bypassing version of ensure_directory()"""
3510 |     if not WRITE_SUPPORT:
3511 |         raise OSError('"os.mkdir" not supported on this platform.')
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
3512 |     dirname, filename = split(path)
3513 |     if dirname and filename and not isdir(dirname):
     |

pkg_resources\__init__.py:3539:23: TRY003 Avoid specifying long messages outside the exception class
     |
3537 |                 content = []
3538 |             else:
3539 |                 raise ValueError("Invalid section heading", line)
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
3540 |         else:
3541 |             content.append(line)
     |

setuptools\_itertools.py:21:19: TRY003 Avoid specifying long messages outside the exception class
   |
19 |         k = key(element)
20 |         if k in seen:
21 |             raise ValueError(f"Duplicate element {element!r} encountered.")
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
22 |         seen_add(k)
23 |         yield element
   |

setuptools\archive_util.py:155:11: TRY003 Avoid specifying long messages outside the exception class
    |
153 |         return tar_member_obj
154 |
155 |     raise LookupError('Got unknown file type')
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
    |

setuptools\build_meta.py:126:15: TRY003 Avoid specifying long messages outside the exception class
    |
124 |           (file,) = matching
125 |       except ValueError:
126 |           raise ValueError(
    |  _______________^
127 | |             'No distribution was found. Ensure that `setup.py` '
128 | |             'is not empty and that it calls `setup()`.'
129 | |         ) from None
    | |_________^ TRY003
130 |       return file
    |

setuptools\command\alias.py:36:19: TRY003 Avoid specifying long messages outside the exception class
   |
34 |           option_base.finalize_options(self)
35 |           if self.remove and len(self.args) != 1:
36 |               raise DistutilsOptionError(
   |  ___________________^
37 | |                 "Must specify exactly one argument (the alias name) when "
38 | |                 "using --remove"
39 | |             )
   | |_____________^ TRY003
40 |
41 |       def run(self):
   |

setuptools\command\bdist_wheel.py:268:19: TRY003 Avoid specifying long messages outside the exception class
    |
266 |             self.compression = self.supported_compressions[self.compression]
267 |         except KeyError:
268 |             raise ValueError(f"Unsupported compression: {self.compression}") from None
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
269 |
270 |         need_options = ("dist_dir", "plat_name", "skip_build")
    |

setuptools\command\bdist_wheel.py:281:19: TRY003 Avoid specifying long messages outside the exception class
    |
279 |             PY_LIMITED_API_PATTERN, self.py_limited_api
280 |         ):
281 |             raise ValueError(f"py-limited-api must match '{PY_LIMITED_API_PATTERN}'")
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
282 |
283 |         # Support legacy [wheel] section for setting universal
    |

setuptools\command\bdist_wheel.py:293:19: TRY003 Avoid specifying long messages outside the exception class
    |
292 |         if self.build_number is not None and not self.build_number[:1].isdigit():
293 |             raise ValueError("Build tag (build-number) must start with a digit.")
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
294 |
295 |     @property
    |

setuptools\command\develop.py:100:19: TRY003 Avoid specifying long messages outside the exception class
    |
 98 |           curdir = _path.normpath(os.curdir)
 99 |           if resolved != curdir:
100 |               raise DistutilsOptionError(
    |  ___________________^
101 | |                 "Can't get a consistent path to setup script from"
102 | |                 " installation directory",
103 | |                 resolved,
104 | |                 curdir,
105 | |             )
    | |_____________^ TRY003
106 |           return path_to_setup
    |

setuptools\command\easy_install.py:349:19: TRY003 Avoid specifying long messages outside the exception class
    |
348 |           if self.editable and not self.build_directory:
349 |               raise DistutilsArgError(
    |  ___________________^
350 | |                 "Must specify a build directory (-b) when using --editable"
351 | |             )
    | |_____________^ TRY003
352 |           if not self.args:
353 |               raise DistutilsArgError(
    |

setuptools\command\easy_install.py:353:19: TRY003 Avoid specifying long messages outside the exception class
    |
351 |               )
352 |           if not self.args:
353 |               raise DistutilsArgError(
    |  ___________________^
354 | |                 "No urls, filenames, or requirements specified (see --help)"
355 | |             )
    | |_____________^ TRY003
356 |
357 |           self.outputs = []
    |

setuptools\command\easy_install.py:381:19: TRY003 Avoid specifying long messages outside the exception class
    |
379 |                 raise ValueError
380 |         except ValueError as e:
381 |             raise DistutilsOptionError("--optimize must be 0, 1, or 2") from e
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
382 |
383 |         return value
    |

setuptools\command\easy_install.py:2197:19: TRY003 Avoid specifying long messages outside the exception class
     |
2195 |         has_path_sep = re.search(r'[\\/]', name)
2196 |         if has_path_sep:
2197 |             raise ValueError("Path separators not allowed in script names")
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
2198 |
2199 |     @classmethod
     |

setuptools\command\editable_wheel.py:85:19: TRY003 Avoid specifying long messages outside the exception class
   |
83 |         _mode = mode.upper()
84 |         if _mode not in _EditableMode.__members__:
85 |             raise errors.OptionError(f"Invalid editable mode: {mode!r}. Try: 'strict'.")
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
86 |
87 |         if _mode == "COMPAT":
   |

setuptools\command\install.py:62:23: TRY003 Avoid specifying long messages outside the exception class
   |
60 |           elif self.single_version_externally_managed:
61 |               if not self.root and not self.record:
62 |                   raise DistutilsArgError(
   |  _______________________^
63 | |                     "You must specify --record or --root when building system"
64 | |                     " packages"
65 | |                 )
   | |_________________^ TRY003
66 |
67 |       def handle_extra_path(self):
   |

setuptools\command\rotate.py:31:19: TRY003 Avoid specifying long messages outside the exception class
   |
29 |       def finalize_options(self):
30 |           if self.match is None:
31 |               raise DistutilsOptionError(
   |  ___________________^
32 | |                 "Must specify one or more (comma-separated) match patterns "
33 | |                 "(e.g. '.zip' or '.egg')"
34 | |             )
   | |_____________^ TRY003
35 |           if self.keep is None:
36 |               raise DistutilsOptionError("Must specify number of files to keep")
   |

setuptools\command\rotate.py:36:19: TRY003 Avoid specifying long messages outside the exception class
   |
34 |             )
35 |         if self.keep is None:
36 |             raise DistutilsOptionError("Must specify number of files to keep")
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
37 |         try:
38 |             self.keep = int(self.keep)
   |

setuptools\command\rotate.py:40:19: TRY003 Avoid specifying long messages outside the exception class
   |
38 |             self.keep = int(self.keep)
39 |         except ValueError as e:
40 |             raise DistutilsOptionError("--keep must be an integer") from e
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
41 |         if isinstance(self.match, str):
42 |             self.match = [convert_path(p.strip()) for p in self.match.split(',')]
   |

setuptools\command\setopt.py:26:11: TRY003 Avoid specifying long messages outside the exception class
   |
24 |         dot = os.name == 'posix' and '.' or ''
25 |         return os.path.expanduser(convert_path("~/%spydistutils.cfg" % dot))
26 |     raise ValueError("config_file() type must be 'local', 'global', or 'user'", kind)
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
   |

setuptools\command\setopt.py:101:19: TRY003 Avoid specifying long messages outside the exception class
    |
 99 |               filenames.append(config_file('local'))
100 |           if len(filenames) > 1:
101 |               raise DistutilsOptionError(
    |  ___________________^
102 | |                 "Must specify only one configuration file option", filenames
103 | |             )
    | |_____________^ TRY003
104 |           (self.filename,) = filenames
    |

setuptools\command\setopt.py:131:19: TRY003 Avoid specifying long messages outside the exception class
    |
129 |         option_base.finalize_options(self)
130 |         if self.command is None or self.option is None:
131 |             raise DistutilsOptionError("Must specify --command *and* --option")
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
132 |         if self.set_value is None and not self.remove:
133 |             raise DistutilsOptionError("Must specify --set-value or --remove")
    |

setuptools\command\setopt.py:133:19: TRY003 Avoid specifying long messages outside the exception class
    |
131 |             raise DistutilsOptionError("Must specify --command *and* --option")
132 |         if self.set_value is None and not self.remove:
133 |             raise DistutilsOptionError("Must specify --set-value or --remove")
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
134 |
135 |     def run(self):
    |

setuptools\config\_apply_pyprojecttoml.py:150:11: TRY003 Avoid specifying long messages outside the exception class
    |
148 |     valid = ", ".join(f"{k} ({v})" for k, v in _CONTENT_TYPES.items())
149 |     msg = f"only the following file extensions are recognized: {valid}."
150 |     raise ValueError(f"Undefined content type for {file}, {msg}")
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
    |

setuptools\config\expand.py:80:19: TRY003 Avoid specifying long messages outside the exception class
   |
78 |             )
79 |         except Exception as e:
80 |             raise AttributeError(f"{self.name} has no attribute {attr}") from e
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
   |

setuptools\config\pyprojecttoml.py:59:15: TRY003 Avoid specifying long messages outside the exception class
   |
58 |         error = f"invalid pyproject.toml config: {ex.name}."
59 |         raise ValueError(f"{error}\n{summary}") from None
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
   |

setuptools\config\pyprojecttoml.py:104:15: TRY003 Avoid specifying long messages outside the exception class
    |
103 |     if not os.path.isfile(filepath):
104 |         raise FileError(f"Configuration file {filepath!r} does not exist.")
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
105 |
106 |     asdict = load_file(filepath) or {}
    |

setuptools\config\pyprojecttoml.py:290:19: TRY003 Avoid specifying long messages outside the exception class
    |
288 |             if "attr" in directive:
289 |                 return _expand.read_attr(directive["attr"], package_dir, root_dir)
290 |             raise ValueError(f"invalid `{specifier}`: {directive!r}")
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
291 |         return None
    |

setuptools\config\setupcfg.py:103:15: TRY003 Avoid specifying long messages outside the exception class
    |
102 |     if not os.path.isfile(filepath):
103 |         raise FileError(f'Configuration file {filepath} does not exist.')
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
104 |
105 |     current_directory = os.getcwd()
    |

setuptools\config\setupcfg.py:335:23: TRY003 Avoid specifying long messages outside the exception class
    |
333 |             key, sep, val = line.partition(separator)
334 |             if sep != separator:
335 |                 raise OptionError(f"Unable to parse option value to dict: {value}")
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
336 |             result[key.strip()] = val.strip()
    |

setuptools\config\setupcfg.py:495:23: TRY003 Avoid specifying long messages outside the exception class
    |
494 |               if section_parser_method is None:
495 |                   raise OptionError(
    |  _______________________^
496 | |                     "Unsupported distribution option section: "
497 | |                     f"[{self.section_prefix}.{section_name}]"
498 | |                 )
    | |_________________^ TRY003
499 |
500 |               section_parser_method(section_options)
    |

setuptools\config\setupcfg.py:585:23: TRY003 Avoid specifying long messages outside the exception class
    |
583 |                   Version(version)
584 |               except InvalidVersion as e:
585 |                   raise OptionError(
    |  _______________________^
586 | |                     f'Version loaded from {value} does not '
587 | |                     f'comply with PEP 440: {version}'
588 | |                 ) from e
    | |_________________^ TRY003
589 |
590 |               return version
    |

setuptools\dist.py:103:15: TRY003 Avoid specifying long messages outside the exception class
    |
101 |           list(itertools.starmap(_check_extra, value.items()))
102 |       except (TypeError, ValueError, AttributeError) as e:
103 |           raise DistutilsSetupError(
    |  _______________^
104 | |             "'extras_require' must be a dictionary whose values are "
105 | |             "strings or lists of strings containing valid project/version "
106 | |             "requirement specifiers."
107 | |         ) from e
    | |_________^ TRY003
    |

setuptools\dist.py:139:11: TRY003 Avoid specifying long messages outside the exception class
    |
137 |         # TODO: should there be a `due_date` here?
138 |         return
139 |     raise DistutilsSetupError(f"{attr} is invalid.")
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
    |

setuptools\dist.py:147:19: TRY003 Avoid specifying long messages outside the exception class
    |
145 |         list(_reqs.parse(value))
146 |         if isinstance(value, (dict, set)):
147 |             raise TypeError("Unordered types are not allowed")
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
148 |     except (TypeError, ValueError) as error:
149 |         tmpl = (
    |

setuptools\dist.py:175:15: TRY003 Avoid specifying long messages outside the exception class
    |
173 | def check_test_suite(dist, attr, value):
174 |     if not isinstance(value, str):
175 |         raise DistutilsSetupError("test_suite must be a string")
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
    |

setuptools\dist.py:916:31: TRY003 Avoid specifying long messages outside the exception class
    |
914 |                             break
915 |                     else:
916 |                         raise AssertionError("Shouldn't be able to get here")
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
917 |
918 |                 elif val == 1:
    |

setuptools\installer.py:58:15: TRY003 Avoid specifying long messages outside the exception class
   |
56 |       opts = dist.get_option_dict('easy_install')
57 |       if 'allow_hosts' in opts:
58 |           raise DistutilsError(
   |  _______________^
59 | |             'the `allow-hosts` option is not supported '
60 | |             'when using pip to install requirements.'
61 | |         )
   | |_________^ TRY003
62 |       quiet = 'PIP_QUIET' not in os.environ and 'PIP_VERBOSE' not in os.environ
63 |       if 'PIP_INDEX_URL' in os.environ:
   |

setuptools\msvc.py:189:15: TRY003 Avoid specifying long messages outside the exception class
    |
187 |     vcvarsall, vcruntime = _msvc14_find_vcvarsall(plat_spec)
188 |     if not vcvarsall:
189 |         raise distutils.errors.DistutilsPlatformError("Unable to find vcvarsall.bat")
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
190 |
191 |     try:
    |

setuptools\msvc.py:626:19: TRY003 Avoid specifying long messages outside the exception class
    |
625 |           if not (reg_vc_vers or self.known_vs_paths):
626 |               raise distutils.errors.DistutilsPlatformError(
    |  ___________________^
627 | |                 'No Microsoft Visual C++ version found'
628 | |             )
    | |_____________^ TRY003
629 |
630 |           vc_vers = set(reg_vc_vers)
    |

setuptools\package_index.py:739:19: TRY003 Avoid specifying long messages outside the exception class
    |
737 |               )
738 |           else:
739 |               raise DistutilsError(
    |  ___________________^
740 | |                 "Can't process plain .py files without an '#egg=name-version'"
741 | |                 " suffix to enable automatic setup script generation."
742 | |             )
    | |_____________^ TRY003
743 |
744 |       dl_blocksize = 8192
    |

setuptools\package_index.py:861:19: TRY003 Avoid specifying long messages outside the exception class
    |
859 |               return None
860 |           if vcs == 'svn':
861 |               raise DistutilsError(
    |  ___________________^
862 | |                 f"Invalid config, SVN download is not supported: {url}"
863 | |             )
    | |_____________^ TRY003
864 |
865 |           filename, _, _ = spec_filename.partition('#')
    |

setuptools\package_index.py:901:15: TRY003 Avoid specifying long messages outside the exception class
    |
899 |     def _invalid_download_html(self, url, headers, filename):
900 |         os.unlink(filename)
901 |         raise DistutilsError(f"Unexpected HTML page found at {url}")
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
902 |
903 |     @staticmethod
    |

setuptools\package_index.py:1069:15: TRY003 Avoid specifying long messages outside the exception class
     |
1067 |     # failing test. We would expect "nonnumeric port". Refs #20.
1068 |     if netloc.endswith(':'):
1069 |         raise http.client.InvalidURL("nonnumeric port: ''")
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
1070 |
1071 |     if scheme in ('http', 'https'):
     |

setuptools\tests\integration\helpers.py:45:19: TRY003 Avoid specifying long messages outside the exception class
   |
43 |             self._obj = ZipFile(filename)
44 |         else:
45 |             raise ValueError(f"{filename} doesn't seem to be a zip or tar.gz")
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
46 |
47 |     def __iter__(self):
   |

setuptools\tests\integration\test_pip_install_sdist.py:177:15: TRY003 Avoid specifying long messages outside the exception class
    |
176 |     if metadata["info"]["yanked"]:
177 |         raise ValueError(f"Release for {package} {version} was yanked")
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
178 |
179 |     version = metadata["info"]["version"]
    |

setuptools\tests\namespaces.py:31:15: TRY003 Avoid specifying long messages outside the exception class
   |
29 |         tmpl = '__path__ = __import__("pkgutil").extend_path(__path__, __name__)'
30 |     else:
31 |         raise ValueError(f"Cannot recognise {impl=} when creating namespaces")
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
32 |
33 |     args = json.dumps(setup_args, indent=4)
   |

setuptools\tests\test_bdist_wheel.py:596:19: TRY003 Avoid specifying long messages outside the exception class
    |
594 |     def _fake_import(name: str, *args, **kwargs):
595 |         if name == "ctypes":
596 |             raise ModuleNotFoundError(f"No module named {name}")
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
597 |
598 |         return importlib.__import__(name, *args, **kwargs)
    |

setuptools\tests\test_packageindex.py:63:19: TRY003 Avoid specifying long messages outside the exception class
   |
61 |             assert 'line' in str(exc)
62 |         else:
63 |             raise AssertionError('Should have raise here!')
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
64 |
65 |     def test_bad_url_double_scheme(self):
   |

setuptools\tests\test_packageindex.py:83:15: TRY003 Avoid specifying long messages outside the exception class
   |
81 |             )
82 |             return
83 |         raise RuntimeError("Did not raise")
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
84 |
85 |     def test_url_ok(self):
   |

setuptools\wheel.py:117:15: TRY003 Avoid specifying long messages outside the exception class
    |
115 |             ):
116 |                 return dirname
117 |         raise ValueError("unsupported wheel format. .dist-info not found")
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
118 |
119 |     def install_as_egg(self, destination_eggdir):
    |

tools\build_launchers.py:122:15: TRY003 Avoid specifying long messages outside the exception class
    |
120 |         return subprocess.check_output(cmd, encoding='utf-8', text=True).strip()
121 |     except subprocess.CalledProcessError as e:
122 |         raise SystemExit("Unable to find MSBuild; check Visual Studio install") from e
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TRY003
    |

Found 69 errors.

@DimitriPapadopoulos
Copy link
Contributor Author

Ouch! That might be new to ruff 0.5.0 that has been released very recently. I'll check that.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Jul 2, 2024

@Avasam How would you handle TRY003? I'm not certain creating lots of specialised exceptions would help maintainability, at least in this specific context. I would tend to ignore this rule in ruff.toml.

Edit: Just noticed your suggestion

Personally I'd just ignore that specific check.

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.

DimitriPapadopoulos added a commit to DimitriPapadopoulos/setuptools that referenced this pull request Jul 9, 2024
Restore the previous functionality, where the function did not return
explicitly in case of exceptions, and hence returned `None`.
@DimitriPapadopoulos DimitriPapadopoulos mentioned this pull request Jul 9, 2024
2 tasks
jaraco added a commit that referenced this pull request Jul 10, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants