Skip to content

Commit

Permalink
Disallow blanket and unused suppressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 27, 2024
1 parent 8a16976 commit 90de434
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@ def load(
if require:
# We could pass `env` and `installer` directly,
# but keeping `*args` and `**kwargs` for backwards compatibility
self.require(*args, **kwargs) # type: ignore
self.require(*args, **kwargs) # type: ignore[arg-type]
return self.resolve()

def resolve(self) -> _ResolvedEntryPoint:
Expand Down
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,3 @@ formats = "zip"


[tool.setuptools_scm]


[tool.pytest-enabler.mypy]
# Disabled due to jaraco/skeleton#143
6 changes: 4 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ extend-select = [

# local
"ANN2", # missing-return-type-*
"FA", # flake8-future-annotations
"F404", # late-future-import
"FA", # flake8-future-annotations
"I", # isort
"PGH", # pygrep-hooks (blanket-* rules)
"PYI", # flake8-pyi
"RUF100", # unused-noqa
"TRY", # tryceratops
"UP", # pyupgrade
"TRY",
"YTT", # flake8-2020
]
ignore = [
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_distutils/compat/py38.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def removeprefix(self, prefix):

def aix_platform(osname, version, release):
try:
import _aix_support # type: ignore
import _aix_support

return _aix_support.aix_platform()
except ImportError:
Expand Down
16 changes: 10 additions & 6 deletions setuptools/config/expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def _load_spec(spec: ModuleSpec, module_name: str) -> ModuleType:
return sys.modules[name]
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module # cache (it also ensures `==` works on loaded items)
spec.loader.exec_module(module) # type: ignore
assert spec.loader is not None
spec.loader.exec_module(module)
return module


Expand Down Expand Up @@ -285,10 +286,10 @@ def find_packages(

from setuptools.discovery import construct_package_dir

if namespaces:
from setuptools.discovery import PEP420PackageFinder as PackageFinder
if not namespaces:
from setuptools.discovery import PackageFinder
else:
from setuptools.discovery import PackageFinder # type: ignore
from setuptools.discovery import PEP420PackageFinder as PackageFinder

root_dir = root_dir or os.curdir
where = kwargs.pop('where', ['.'])
Expand Down Expand Up @@ -352,14 +353,17 @@ def canonic_data_files(
]


def entry_points(text: str, text_source="entry-points") -> dict[str, dict]:
def entry_points(
text: str, text_source: str = "entry-points"
) -> dict[str, dict[str, str]]:
"""Given the contents of entry-points file,
process it into a 2-level dictionary (``dict[str, dict[str, str]]``).
The first level keys are entry-point groups, the second level keys are
entry-point names, and the second level values are references to objects
(that correspond to the entry-point value).
"""
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore
# TODO: Explain why passing None is fine here when ConfigParser.default_section expects to be str
parser = ConfigParser(default_section=None, delimiters=("=",)) # type: ignore[call-overload]
parser.optionxform = str # case sensitive
parser.read_string(text, text_source)
groups = {k: dict(v.items()) for k, v in parser.items()}
Expand Down
9 changes: 5 additions & 4 deletions setuptools/config/pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def validate(config: dict, filepath: StrPath) -> bool:

trove_classifier = validator.FORMAT_FUNCTIONS.get("trove-classifier")
if hasattr(trove_classifier, "_disable_download"):
# Improve reproducibility by default. See issue 31 for validate-pyproject.
trove_classifier._disable_download() # type: ignore
# Improve reproducibility by default. See https://github.com/abravalheri/validate-pyproject/issues/31
trove_classifier._disable_download() # type: ignore[union-attr]

try:
return validator.validate(config)
Expand Down Expand Up @@ -327,7 +327,7 @@ def _obtain_readme(self, dist: Distribution) -> dict[str, str] | None:

def _obtain_entry_points(
self, dist: Distribution, package_dir: Mapping[str, str]
) -> dict[str, dict] | None:
) -> dict[str, dict[str, Any]] | None:
fields = ("entry-points", "scripts", "gui-scripts")
if not any(field in self.dynamic for field in fields):
return None
Expand All @@ -337,7 +337,8 @@ def _obtain_entry_points(
return None

groups = _expand.entry_points(text)
expanded = {"entry-points": groups}
# Any is str | dict[str, str], but causes variance issues
expanded: dict[str, dict[str, Any]] = {"entry-points": groups}

def _set_scripts(field: str, group: str):
if group in groups:
Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/config/test_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ini2toml.api import LiteTranslator
from packaging.metadata import Metadata

import setuptools # noqa ensure monkey patch to metadata
import setuptools # noqa: F401 # ensure monkey patch to metadata
from setuptools.command.egg_info import write_requirements
from setuptools.config import expand, pyprojecttoml, setupcfg
from setuptools.config._apply_pyprojecttoml import _MissingDynamic, _some_attrgetter
Expand Down
8 changes: 4 additions & 4 deletions setuptools/tests/test_editable_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,18 +878,18 @@ class TestOverallBehaviour:
"otherfile.py": "",
"mypkg": {
"__init__.py": "",
"mod1.py": FLAT_LAYOUT["mypkg"]["mod1.py"], # type: ignore
"mod1.py": FLAT_LAYOUT["mypkg"]["mod1.py"], # type: ignore[index]
},
"other": FLAT_LAYOUT["mypkg"]["subpackage"], # type: ignore
"other": FLAT_LAYOUT["mypkg"]["subpackage"], # type: ignore[index]
},
"namespace": {
"pyproject.toml": dedent(PYPROJECT),
"MANIFEST.in": EXAMPLE["MANIFEST.in"],
"otherfile.py": "",
"src": {
"mypkg": {
"mod1.py": FLAT_LAYOUT["mypkg"]["mod1.py"], # type: ignore
"subpackage": FLAT_LAYOUT["mypkg"]["subpackage"], # type: ignore
"mod1.py": FLAT_LAYOUT["mypkg"]["mod1.py"], # type: ignore[index]
"subpackage": FLAT_LAYOUT["mypkg"]["subpackage"], # type: ignore[index]
},
},
},
Expand Down

0 comments on commit 90de434

Please sign in to comment.