Skip to content

Commit

Permalink
👹 Feed the hobgoblins (delint).
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 6, 2024
1 parent 7d632f2 commit 9f2d682
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 63 deletions.
1 change: 1 addition & 0 deletions importlib_metadata/__init__.py
Expand Up @@ -769,6 +769,7 @@ class Lookup:
"""
A micro-optimized class for searching a (fast) path for metadata.
"""

def __init__(self, path: FastPath):
"""
Calculate all of the children representing metadata.
Expand Down
47 changes: 21 additions & 26 deletions importlib_metadata/_meta.py
Expand Up @@ -9,30 +9,27 @@


class PackageMetadata(Protocol):
def __len__(self) -> int:
... # pragma: no cover
def __len__(self) -> int: ... # pragma: no cover

def __contains__(self, item: str) -> bool:
... # pragma: no cover
def __contains__(self, item: str) -> bool: ... # pragma: no cover

def __getitem__(self, key: str) -> str:
... # pragma: no cover
def __getitem__(self, key: str) -> str: ... # pragma: no cover

def __iter__(self) -> Iterator[str]:
... # pragma: no cover
def __iter__(self) -> Iterator[str]: ... # pragma: no cover

@overload
def get(self, name: str, failobj: None = None) -> Optional[str]:
... # pragma: no cover
def get(
self, name: str, failobj: None = None
) -> Optional[str]: ... # pragma: no cover

@overload
def get(self, name: str, failobj: _T) -> Union[str, _T]:
... # pragma: no cover
def get(self, name: str, failobj: _T) -> Union[str, _T]: ... # pragma: no cover

# overload per python/importlib_metadata#435
@overload
def get_all(self, name: str, failobj: None = None) -> Optional[List[Any]]:
... # pragma: no cover
def get_all(
self, name: str, failobj: None = None
) -> Optional[List[Any]]: ... # pragma: no cover

@overload
def get_all(self, name: str, failobj: _T) -> Union[List[Any], _T]:
Expand All @@ -52,21 +49,19 @@ class SimplePath(Protocol):
A minimal subset of pathlib.Path required by Distribution.
"""

def joinpath(self, other: Union[str, os.PathLike[str]]) -> SimplePath:
... # pragma: no cover
def joinpath(
self, other: Union[str, os.PathLike[str]]
) -> SimplePath: ... # pragma: no cover

def __truediv__(self, other: Union[str, os.PathLike[str]]) -> SimplePath:
... # pragma: no cover
def __truediv__(
self, other: Union[str, os.PathLike[str]]
) -> SimplePath: ... # pragma: no cover

@property
def parent(self) -> SimplePath:
... # pragma: no cover
def parent(self) -> SimplePath: ... # pragma: no cover

def read_text(self, encoding=None) -> str:
... # pragma: no cover
def read_text(self, encoding=None) -> str: ... # pragma: no cover

def read_bytes(self) -> bytes:
... # pragma: no cover
def read_bytes(self) -> bytes: ... # pragma: no cover

def exists(self) -> bool:
... # pragma: no cover
def exists(self) -> bool: ... # pragma: no cover
1 change: 1 addition & 0 deletions importlib_metadata/_py39compat.py
@@ -1,6 +1,7 @@
"""
Compatibility layer with Python 3.8/3.9
"""

from typing import TYPE_CHECKING, Any, Optional

if TYPE_CHECKING: # pragma: no cover
Expand Down
15 changes: 5 additions & 10 deletions tests/_path.py
Expand Up @@ -17,20 +17,15 @@ class Symlink(str):

@runtime_checkable
class TreeMaker(Protocol):
def __truediv__(self, *args, **kwargs):
... # pragma: no cover
def __truediv__(self, *args, **kwargs): ... # pragma: no cover

def mkdir(self, **kwargs):
... # pragma: no cover
def mkdir(self, **kwargs): ... # pragma: no cover

def write_text(self, content, **kwargs):
... # pragma: no cover
def write_text(self, content, **kwargs): ... # pragma: no cover

def write_bytes(self, content):
... # pragma: no cover
def write_bytes(self, content): ... # pragma: no cover

def symlink_to(self, target):
... # pragma: no cover
def symlink_to(self, target): ... # pragma: no cover


def _ensure_tree_maker(obj: Union[str, TreeMaker]) -> TreeMaker:
Expand Down
16 changes: 7 additions & 9 deletions tests/fixtures.py
Expand Up @@ -140,15 +140,13 @@ class DistInfoPkgEditable(DistInfoPkg):
some_hash = '524127ce937f7cb65665130c695abd18ca386f60bb29687efb976faa1596fdcc'
files: FilesSpec = {
'distinfo_pkg-1.0.0.dist-info': {
'direct_url.json': json.dumps(
{
"archive_info": {
"hash": f"sha256={some_hash}",
"hashes": {"sha256": f"{some_hash}"},
},
"url": "file:///path/to/distinfo_pkg-1.0.0.editable-py3-none-any.whl",
}
)
'direct_url.json': json.dumps({
"archive_info": {
"hash": f"sha256={some_hash}",
"hashes": {"sha256": f"{some_hash}"},
},
"url": "file:///path/to/distinfo_pkg-1.0.0.editable-py3-none-any.whl",
})
},
}

Expand Down
32 changes: 14 additions & 18 deletions tests/test_main.py
Expand Up @@ -304,12 +304,10 @@ def test_sortable(self):
"""
EntryPoint objects are sortable, but result is undefined.
"""
sorted(
[
EntryPoint(name='b', value='val', group='group'),
EntryPoint(name='a', value='val', group='group'),
]
)
sorted([
EntryPoint(name='b', value='val', group='group'),
EntryPoint(name='a', value='val', group='group'),
])


class FileSystem(
Expand Down Expand Up @@ -376,18 +374,16 @@ def test_packages_distributions_all_module_types(self):
'all_distributions-1.0.0.dist-info': metadata,
}
for i, suffix in enumerate(suffixes):
files.update(
{
f'importable-name {i}{suffix}': '',
f'in_namespace_{i}': {
f'mod{suffix}': '',
},
f'in_package_{i}': {
'__init__.py': '',
f'mod{suffix}': '',
},
}
)
files.update({
f'importable-name {i}{suffix}': '',
f'in_namespace_{i}': {
f'mod{suffix}': '',
},
f'in_package_{i}': {
'__init__.py': '',
f'mod{suffix}': '',
},
})
metadata.update(RECORD=fixtures.build_record(files))
fixtures.build_files(files, prefix=self.site_dir)

Expand Down

0 comments on commit 9f2d682

Please sign in to comment.