diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index db3235e1..52c81eac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,12 +14,12 @@ repos: - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.276 + rev: v0.0.282 hooks: - id: ruff diff --git a/src/npe2/implements.pyi b/src/npe2/implements.pyi index 3418484e..61f83fde 100644 --- a/src/npe2/implements.pyi +++ b/src/npe2/implements.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, List, TypeVar +from typing import Any, Callable, TypeVar from pydantic import BaseModel as BaseModel @@ -13,7 +13,7 @@ def reader( *, id: str, title: str, - filename_patterns: List[str], + filename_patterns: list[str], accepts_directories: bool = False, ensure_args_valid: bool = False, ) -> Callable[[T], T]: @@ -23,8 +23,8 @@ def writer( *, id: str, title: str, - layer_types: List[str], - filename_extensions: List[str] = [], # noqa: B006 + layer_types: list[str], + filename_extensions: list[str] = [], # noqa: B006 display_name: str = "", ensure_args_valid: bool = False, ) -> Callable[[T], T]: diff --git a/tests/test_contributions.py b/tests/test_contributions.py index 5e580bb2..af5a778c 100644 --- a/tests/test_contributions.py +++ b/tests/test_contributions.py @@ -85,10 +85,10 @@ def test_writer_valid_layer_type_expressions(expr, uses_sample_plugin): def test_basic_iter_reader(uses_sample_plugin, plugin_manager: PluginManager, tmp_path): tmp_path = str(tmp_path) assert not list(plugin_manager.iter_compatible_readers("")) - reader = list(plugin_manager.iter_compatible_readers(tmp_path))[0] + reader = next(iter(plugin_manager.iter_compatible_readers(tmp_path))) assert reader.command == f"{SAMPLE_PLUGIN_NAME}.some_reader" - reader = list(plugin_manager.iter_compatible_readers([tmp_path, tmp_path]))[0] + reader = next(iter(plugin_manager.iter_compatible_readers([tmp_path, tmp_path]))) assert reader.command == f"{SAMPLE_PLUGIN_NAME}.some_reader" with pytest.raises(ValueError): @@ -108,7 +108,7 @@ def test_widgets(uses_sample_plugin, plugin_manager: PluginManager): def test_sample(uses_sample_plugin, plugin_manager: PluginManager): - plugin, contribs = list(plugin_manager.iter_sample_data())[0] + plugin, contribs = next(iter(plugin_manager.iter_sample_data())) assert plugin == SAMPLE_PLUGIN_NAME assert len(contribs) == 2 ctrbA, ctrbB = contribs @@ -125,12 +125,12 @@ def test_sample(uses_sample_plugin, plugin_manager: PluginManager): def test_directory_reader(uses_sample_plugin, plugin_manager: PluginManager, tmp_path): - reader = list(plugin_manager.iter_compatible_readers(str(tmp_path)))[0] + reader = next(iter(plugin_manager.iter_compatible_readers(str(tmp_path)))) assert reader.command == f"{SAMPLE_PLUGIN_NAME}.some_reader" def test_themes(uses_sample_plugin, plugin_manager: PluginManager): - theme = list(plugin_manager.iter_themes())[0] + theme = next(iter(plugin_manager.iter_themes())) assert theme.label == "SampleTheme" diff --git a/tests/test_manifest.py b/tests/test_manifest.py index f4b2248e..70addc04 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -38,7 +38,7 @@ def test_discover(uses_sample_plugin): [(manifest, distribution, error)] = discover_results assert manifest and manifest.name == SAMPLE_PLUGIN_NAME assert distribution - entrypoint = tuple(distribution.entry_points)[0] + entrypoint = next(iter(distribution.entry_points)) assert entrypoint and entrypoint.group == "napari.manifest" == ENTRY_POINT assert entrypoint.value == f"{SAMPLE_MODULE_NAME}:napari.yaml" assert error is None @@ -82,12 +82,12 @@ def test_discover_errors(tmp_path: Path): res_a, res_b = discover_results assert res_a.manifest is None assert res_a.distribution - assert tuple(res_a.distribution.entry_points)[0].value == bad_value + assert next(iter(res_a.distribution.entry_points)).value == bad_value assert "Cannot find module 'asdfsad'" in str(res_a.error) assert res_b.manifest is None assert res_b.distribution - assert tuple(res_b.distribution.entry_points)[0].value == "module:napari.yaml" + assert next(iter(res_b.distribution.entry_points)).value == "module:napari.yaml" assert isinstance(res_b.error, ValidationError) diff --git a/tests/test_setuptools_plugin.py b/tests/test_setuptools_plugin.py index d039cf1b..4780fbcf 100644 --- a/tests/test_setuptools_plugin.py +++ b/tests/test_setuptools_plugin.py @@ -11,16 +11,14 @@ ROOT = Path(__file__).parent.parent TEMPLATE = Path("my_module") / "_napari.yaml" -PYPROJECT = """ +PYPROJECT = f""" [build-system] -requires = ["setuptools", "wheel", "npe2 @ file://{}"] +requires = ["setuptools", "wheel", "npe2 @ file://{ROOT}"] build-backend = "setuptools.build_meta" [tool.npe2] -template="{}" -""".format( - ROOT, TEMPLATE -) +template="{TEMPLATE}" +""" @pytest.mark.skipif(not os.getenv("CI"), reason="slow, only run on CI") diff --git a/tests/test_validations.py b/tests/test_validations.py index 847f7dcf..d5a8e0a3 100644 --- a/tests/test_validations.py +++ b/tests/test_validations.py @@ -162,7 +162,7 @@ def _valid_mutator_no_contributions_None(data): def test_valid_mutations(mutator, uses_sample_plugin): assert mutator.__name__.startswith("_valid") - pm = list(PluginManifest.discover())[0] + pm = next(iter(PluginManifest.discover())) assert pm.manifest # make sure the data is a copy as we'll mutate it data = json.loads(pm.manifest.json(exclude_unset=True))