From b48ce302c64e8d474feca1e33aedaaff02eaa27f Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Thu, 19 Jan 2023 06:17:57 -0700 Subject: [PATCH] chore: autoupdate pre-commit This lets remove a bunch of # type: ignores --- .pre-commit-config.yaml | 13 ++++++----- docs/tutorials/authentication.md | 2 +- pystac_client/collection_client.py | 9 +++----- pystac_client/stac_api_io.py | 3 ++- tests/test_cli.py | 2 +- tests/test_client.py | 20 ++++++++--------- tests/test_collection_client.py | 6 ++--- tests/test_item_search.py | 36 +++++++++++++++--------------- tests/test_stac_api_io.py | 6 ++--- 9 files changed, 48 insertions(+), 49 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f423f066..6b7cf482 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,36 +3,37 @@ repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 22.12.0 hooks: - id: black - repo: https://github.com/codespell-project/codespell - rev: v2.1.0 + rev: v2.2.2 hooks: - id: codespell args: [--ignore-words=.codespellignore] types_or: [jupyter, markdown, python, shell] - repo: https://github.com/PyCQA/doc8 - rev: 0.11.2 + rev: v1.1.1 hooks: - id: doc8 additional_dependencies: - importlib_metadata < 5; python_version == "3.7" - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 6.0.0 hooks: - id: flake8 - repo: https://github.com/pycqa/isort - rev: 5.10.1 + rev: 5.11.4 hooks: - id: isort name: isort (python) - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.960 + rev: v0.991 hooks: - id: mypy files: ".*\\.py$" additional_dependencies: - pystac + - pytest-vcr - types-requests - types-python-dateutil diff --git a/docs/tutorials/authentication.md b/docs/tutorials/authentication.md index ec5961f6..7639388e 100644 --- a/docs/tutorials/authentication.md +++ b/docs/tutorials/authentication.md @@ -4,7 +4,7 @@ While not integrated into this library directly, pystac-client provides a series ## Basic auth -Pystac-client supports HTTP basic authentication by simply exposing the ability to define headers to be used when sending requets. Simply encode the token and provide the header. +Pystac-client supports HTTP basic authentication by simply exposing the ability to define headers to be used when sending requests. Simply encode the token and provide the header. ```python import base64 diff --git a/pystac_client/collection_client.py b/pystac_client/collection_client.py index 99722923..d3dd0cce 100644 --- a/pystac_client/collection_client.py +++ b/pystac_client/collection_client.py @@ -100,14 +100,12 @@ def get_items(self) -> Iterator["Item_Type"]: url=link.href, method="GET", stac_io=stac_io, - modifier=self.modifier, # type: ignore + modifier=self.modifier, ) yield from search.items() else: for item in super().get_items(): - # what is going on with mypy here? - # error: Too many arguments [call-arg] - call_modifier(self.modifier, item) # type: ignore + call_modifier(self.modifier, item) yield item def get_item(self, id: str, recursive: bool = False) -> Optional["Item_Type"]: @@ -155,7 +153,6 @@ def get_item(self, id: str, recursive: bool = False) -> Optional["Item_Type"]: break if item: - # error: Too many arguments [call-arg] - call_modifier(self.modifier, item) # type: ignore + call_modifier(self.modifier, item) return item diff --git a/pystac_client/stac_api_io.py b/pystac_client/stac_api_io.py index 5d6b05a3..2938a4cc 100644 --- a/pystac_client/stac_api_io.py +++ b/pystac_client/stac_api_io.py @@ -168,7 +168,8 @@ def stac_object_from_dict( root: Optional["Catalog_Type"] = None, preserve_dict: bool = True, ) -> "STACObject_Type": - """Deserializes a :class:`~pystac.STACObject` sub-class instance from a dictionary. + """Deserializes a :class:`~pystac.STACObject` sub-class instance from a + dictionary. Args: d : The dictionary to deserialize diff --git a/tests/test_cli.py b/tests/test_cli.py index e7b5c95a..14d1292f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -5,7 +5,7 @@ class TestCLI: - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_item_search(self, script_runner: ScriptRunner) -> None: args = [ "stac-client", diff --git a/tests/test_client.py b/tests/test_client.py index d9a7f66a..6b5ecf2d 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -21,7 +21,7 @@ class TestAPI: - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_instance(self) -> None: api = Client.open(STAC_URLS["PLANETARY-COMPUTER"]) @@ -30,7 +30,7 @@ def test_instance(self) -> None: assert str(api) == "" - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_links(self) -> None: api = Client.open(STAC_URLS["PLANETARY-COMPUTER"]) @@ -57,7 +57,7 @@ def test_spec_conformance(self) -> None: assert client._stac_io.conforms_to(ConformanceClasses.CORE) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_no_conformance(self) -> None: """Should raise a NotImplementedError if no conformance info can be found. Luckily, the test API doesn't publish a "conformance" link so we can just @@ -73,7 +73,7 @@ def test_no_conformance(self) -> None: with pytest.raises(NotImplementedError): client._stac_io.assert_conforms_to(ConformanceClasses.ITEM_SEARCH) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_no_stac_core_conformance(self) -> None: """Should raise a NotImplementedError if the API does not conform to the STAC API - Core spec.""" @@ -87,7 +87,7 @@ def test_no_stac_core_conformance(self) -> None: assert client._stac_io.conforms_to(ConformanceClasses.ITEM_SEARCH) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_from_file(self) -> None: api = Client.from_file(STAC_URLS["PLANETARY-COMPUTER"]) @@ -448,7 +448,7 @@ def test_opening_a_collection(self) -> None: class TestAPISearch: - @pytest.fixture(scope="function") # type: ignore[misc] + @pytest.fixture(scope="function") def api(self) -> Client: return Client.from_file(str(TEST_DATA / "planetary-computer-root.json")) @@ -513,7 +513,7 @@ def test_json_search_link(self, api: Client) -> None: api.add_link(search_link) api.search(limit=1, max_items=1, collections="naip") - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_search_max_items_unlimited_default(self, api: Client) -> None: search = api.search( bbox=[-73.21, 43.99, -73.12, 45.05], @@ -533,7 +533,7 @@ def __call__(self, x: Modifiable) -> None: class TestSigning: - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_signing(self) -> None: sign = MySign() # sign is callable, but mypy keeps trying to interpret it as a "MySign" object. @@ -543,7 +543,7 @@ def test_signing(self) -> None: collection = client.get_collection("cil-gdpcir-cc0") assert collection assert isinstance(collection, CollectionClient) - assert collection.modifier is sign # type: ignore + assert collection.modifier is sign assert sign.call_count == 1 collection.get_item("cil-gdpcir-INM-INM-CM5-0-ssp585-r1i1p1f1-day") @@ -577,7 +577,7 @@ def test_signing(self) -> None: search.item_collection() assert sign.call_count == 11 - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_sign_with_return_warns(self) -> None: def modifier_ok(x: Any) -> Any: return x diff --git a/tests/test_collection_client.py b/tests/test_collection_client.py index e8d1701d..fac9ab94 100644 --- a/tests/test_collection_client.py +++ b/tests/test_collection_client.py @@ -7,7 +7,7 @@ class TestCollectionClient: - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_instance(self) -> None: client = Client.open(STAC_URLS["PLANETARY-COMPUTER"]) collection = client.get_collection("aster-l1t") @@ -15,7 +15,7 @@ def test_instance(self) -> None: assert isinstance(collection, CollectionClient) assert str(collection) == "" - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_get_items(self) -> None: client = Client.open(STAC_URLS["PLANETARY-COMPUTER"]) collection = client.get_collection("aster-l1t") @@ -24,7 +24,7 @@ def test_get_items(self) -> None: assert item.collection_id == collection.id return - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_get_item(self) -> None: client = Client.open(STAC_URLS["PLANETARY-COMPUTER"]) collection = client.get_collection("aster-l1t") diff --git a/tests/test_item_search.py b/tests/test_item_search.py index bdfc76f4..bf7efc31 100644 --- a/tests/test_item_search.py +++ b/tests/test_item_search.py @@ -32,7 +32,7 @@ class TestItemPerformance: - @pytest.fixture(scope="function") # type: ignore[misc] + @pytest.fixture(scope="function") def single_href(self) -> str: item_href = "https://planetarycomputer.microsoft.com/api/stac/v1/collections/{collections}/items/{ids}".format( collections=ITEM_EXAMPLE["collections"], ids=ITEM_EXAMPLE["ids"] @@ -62,7 +62,7 @@ def test_single_item_search( class TestItemSearchParams: - @pytest.fixture(scope="function") # type: ignore[misc] + @pytest.fixture(scope="function") def sample_client(self) -> Client: api_content = read_data_file("planetary-computer-root.json", parse_json=True) return Client.from_dict(api_content) @@ -451,18 +451,18 @@ def test_sortby(self) -> None: ) with pytest.raises(Exception): - ItemSearch(url=SEARCH_URL, sortby=1) # type: ignore[arg-type] + ItemSearch(url=SEARCH_URL, sortby=1) # type: ignore with pytest.raises(Exception): - ItemSearch(url=SEARCH_URL, sortby=[1]) # type: ignore[arg-type] + ItemSearch(url=SEARCH_URL, sortby=[1]) # type: ignore def test_fields(self) -> None: with pytest.raises(Exception): - ItemSearch(url=SEARCH_URL, fields=1) # type: ignore[arg-type] + ItemSearch(url=SEARCH_URL, fields=1) # type: ignore with pytest.raises(Exception): - ItemSearch(url=SEARCH_URL, fields=[1]) # type: ignore[list-item] + ItemSearch(url=SEARCH_URL, fields=[1]) # type: ignore search = ItemSearch(url=SEARCH_URL, fields="id,collection,+foo,-bar") assert search.get_parameters()["fields"] == { @@ -504,7 +504,7 @@ def test_fields(self) -> None: class TestItemSearch: - @pytest.fixture(scope="function") # type: ignore[misc] + @pytest.fixture(scope="function") def astraea_api(self) -> Client: api_content = read_data_file("astraea_api.json", parse_json=True) return Client.from_dict(api_content) @@ -539,7 +539,7 @@ def test_method_params(self) -> None: assert all(key in params for key in params_in) assert all(isinstance(params[key], str) for key in params_in) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_results(self) -> None: search = ItemSearch( url=SEARCH_URL, @@ -551,7 +551,7 @@ def test_results(self) -> None: assert all(isinstance(item, pystac.Item) for item in results) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_ids_results(self) -> None: ids = [ "S2B_MSIL2A_20210610T115639_N0212_R066_T33XXG_20210613T185024.SAFE", @@ -566,7 +566,7 @@ def test_ids_results(self) -> None: assert len(results) == 1 assert all(item.id in ids for item in results) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_datetime_results(self) -> None: # Datetime range string datetime_ = "2019-01-01T00:00:01Z/2019-01-01T00:00:10Z" @@ -585,7 +585,7 @@ def test_datetime_results(self) -> None: min_datetime <= item.datetime <= (max_datetime + timedelta(seconds=1)) ) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_intersects_results(self) -> None: # GeoJSON-like dict intersects_dict = { @@ -619,7 +619,7 @@ def __geo_interface__(self) -> Dict[str, Any]: new_results = search.items() assert all(isinstance(item, pystac.Item) for item in new_results) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_result_paging(self) -> None: search = ItemSearch( url=SEARCH_URL, @@ -635,7 +635,7 @@ def test_result_paging(self) -> None: assert pages[1] != pages[2] assert pages[1].items != pages[2].items - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_item_collection(self) -> None: search = ItemSearch( url=SEARCH_URL, @@ -648,8 +648,8 @@ def test_item_collection(self) -> None: assert isinstance(item_collection, pystac.ItemCollection) assert len(item_collection) == 20 - @pytest.mark.vcr # type: ignore[misc] - @pytest.mark.parametrize( # type: ignore[misc] + @pytest.mark.vcr + @pytest.mark.parametrize( "method, alternative, is_sequence, is_pystac", [ ("get_item_collections", "pages", True, True), @@ -688,7 +688,7 @@ def test_deprecations( assert result == expected - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_items_as_dicts(self) -> None: search = ItemSearch( url=SEARCH_URL, @@ -701,7 +701,7 @@ def test_items_as_dicts(self) -> None: class TestItemSearchQuery: - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_query_shortcut_syntax(self) -> None: search = ItemSearch( url=SEARCH_URL, @@ -723,7 +723,7 @@ def test_query_shortcut_syntax(self) -> None: assert len(items2) == 1 assert items1[0].id == items2[0].id - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_query_json_syntax(self) -> None: # with a list of json strs (format of CLI argument to ItemSearch) diff --git a/tests/test_stac_api_io.py b/tests/test_stac_api_io.py index 5025b191..aaa11452 100644 --- a/tests/test_stac_api_io.py +++ b/tests/test_stac_api_io.py @@ -13,20 +13,20 @@ class TestSTAC_IOOverride: - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_request_input(self) -> None: stac_api_io = StacApiIO() response = stac_api_io.read_text(STAC_URLS["PLANETARY-COMPUTER"]) assert isinstance(response, str) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_str_input(self) -> None: stac_api_io = StacApiIO() response = stac_api_io.read_text(STAC_URLS["PLANETARY-COMPUTER"]) assert isinstance(response, str) - @pytest.mark.vcr # type: ignore[misc] + @pytest.mark.vcr def test_http_error(self) -> None: stac_api_io = StacApiIO() # Attempt to access an authenticated endpoint