Skip to content

Commit

Permalink
chore: pyupgrade to 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Aug 9, 2024
1 parent e3b68f6 commit ecfc58e
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.17.0
hooks:
- id: pyupgrade
args:
- "--py39-plus"
- "--py310-plus"

- repo: local
hooks:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ test = [
"html5lib~=1.1",
"jinja2<4.0",
"jsonschema~=4.18",
"mypy~=1.2",
"mypy~=1.11",
"orjson~=3.8",
"pre-commit~=3.2",
"pytest-cov~=5.0",
Expand Down Expand Up @@ -104,7 +104,7 @@ max-line-length = 88

[tool.ruff]
line-length = 88
select = ["E", "F", "I"]
lint.select = ["E", "F", "I"]

[tool.pytest.ini_options]
filterwarnings = ["error"]
Expand Down
15 changes: 8 additions & 7 deletions pystac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
PySTAC is a library for working with SpatioTemporal Asset Catalogs (STACs)
"""

__all__ = [
"__version__",
"TemplateError",
Expand Down Expand Up @@ -44,7 +45,7 @@

import os
import warnings
from typing import Any, Optional
from typing import Any

from pystac.errors import (
TemplateError,
Expand Down Expand Up @@ -136,7 +137,7 @@
)


def read_file(href: HREF, stac_io: Optional[StacIO] = None) -> STACObject:
def read_file(href: HREF, stac_io: StacIO | None = None) -> STACObject:
"""Reads a STAC object from a file.
This method will return either a Catalog, a Collection, or an Item based on what
Expand Down Expand Up @@ -168,8 +169,8 @@ def read_file(href: HREF, stac_io: Optional[StacIO] = None) -> STACObject:
def write_file(
obj: STACObject,
include_self_link: bool = True,
dest_href: Optional[HREF] = None,
stac_io: Optional[StacIO] = None,
dest_href: HREF | None = None,
stac_io: StacIO | None = None,
) -> None:
"""Writes a STACObject to a file.
Expand Down Expand Up @@ -202,9 +203,9 @@ def write_file(

def read_dict(
d: dict[str, Any],
href: Optional[str] = None,
root: Optional[Catalog] = None,
stac_io: Optional[StacIO] = None,
href: str | None = None,
root: Catalog | None = None,
stac_io: StacIO | None = None,
) -> STACObject:
"""Reads a :class:`~STACObject` or :class:`~ItemCollection` from a JSON-like dict
representing a serialized STAC object.
Expand Down
3 changes: 1 addition & 2 deletions pystac/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import os
import warnings
from collections.abc import Iterable, Iterator
from collections.abc import Callable, Iterable, Iterator
from copy import deepcopy
from itertools import chain
from typing import (
TYPE_CHECKING,
Any,
Callable,
TypeVar,
Union,
cast,
Expand Down
10 changes: 4 additions & 6 deletions pystac/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Union
from typing import Any


class TemplateError(Exception):
Expand Down Expand Up @@ -28,7 +28,7 @@ def __init__(
self,
bad_dict: dict[str, Any],
expected: type,
extra_message: Optional[str] = "",
extra_message: str | None = "",
):
"""
Construct an exception with an appropriate error message from bad_dict and the
Expand Down Expand Up @@ -88,9 +88,7 @@ class RequiredPropertyMissing(Exception):
prop: The property that is missing
"""

def __init__(
self, obj: Union[str, Any], prop: str, msg: Optional[str] = None
) -> None:
def __init__(self, obj: str | Any, prop: str, msg: str | None = None) -> None:
msg = msg or f"{repr(obj)} does not have required property {prop}"
super().__init__(msg)

Expand All @@ -109,7 +107,7 @@ class STACValidationError(Exception):
the ``jsonschema.ValidationError``.
"""

def __init__(self, message: str, source: Optional[Any] = None):
def __init__(self, message: str, source: Any | None = None):
super().__init__(message)
self.source = source

Expand Down
14 changes: 7 additions & 7 deletions pystac/extensions/mgrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import re
from re import Pattern
from typing import Any, Literal, Optional, Union
from typing import Any, Literal, Union

import pystac
from pystac.extensions.base import ExtensionManagementMixin, PropertiesExtension
Expand Down Expand Up @@ -132,7 +132,7 @@ def validated_grid_square(v: str) -> str:
return v


def validated_utm_zone(v: Optional[int]) -> Optional[int]:
def validated_utm_zone(v: int | None) -> int | None:
if v is not None and not isinstance(v, int):
raise ValueError("Invalid MGRS utm zone: must be None or int")
if v is not None and v not in UTM_ZONES:
Expand Down Expand Up @@ -175,7 +175,7 @@ def apply(
self,
latitude_band: str,
grid_square: str,
utm_zone: Optional[int] = None,
utm_zone: int | None = None,
) -> None:
"""Applies MGRS extension properties to the extended Item.
Expand All @@ -189,7 +189,7 @@ def apply(
self.utm_zone = validated_utm_zone(utm_zone)

@property
def latitude_band(self) -> Optional[str]:
def latitude_band(self) -> str | None:
"""Get or sets the latitude band of the datasource."""
return self._get_property(LATITUDE_BAND_PROP, str)

Expand All @@ -200,7 +200,7 @@ def latitude_band(self, v: str) -> None:
)

@property
def grid_square(self) -> Optional[str]:
def grid_square(self) -> str | None:
"""Get or sets the latitude band of the datasource."""
return self._get_property(GRID_SQUARE_PROP, str)

Expand All @@ -211,12 +211,12 @@ def grid_square(self, v: str) -> None:
)

@property
def utm_zone(self) -> Optional[int]:
def utm_zone(self) -> int | None:
"""Get or sets the latitude band of the datasource."""
return self._get_property(UTM_ZONE_PROP, int)

@utm_zone.setter
def utm_zone(self, v: Optional[int]) -> None:
def utm_zone(self, v: int | None) -> None:
self._set_property(UTM_ZONE_PROP, validated_utm_zone(v), pop_if_none=True)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def get_object_links(self, so: STACObject) -> list[str] | None:


@contextmanager
def ignore_deprecated() -> Generator[None, None, None]:
def ignore_deprecated() -> Generator[None]:
"""Context manager for suppressing the :class:`pystac.DeprecatedWarning`
when creating a deprecated :class:`~pystac.Item` or :class:`~pystac.Collection`
from a dictionary."""
Expand Down
3 changes: 2 additions & 1 deletion pystac/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import warnings
from abc import ABC, abstractmethod
from collections import OrderedDict
from collections.abc import Callable
from string import Formatter
from typing import TYPE_CHECKING, Any, Callable
from typing import TYPE_CHECKING, Any

import pystac
from pystac.utils import is_file_path
Expand Down
16 changes: 8 additions & 8 deletions pystac/provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from html import escape
from typing import Any, Optional
from typing import Any

from pystac.html.jinja_env import get_jinja_env
from pystac.utils import StringEnum
Expand Down Expand Up @@ -36,16 +36,16 @@ class Provider:
name: str
"""The name of the organization or the individual."""

description: Optional[str]
description: str | None
"""Optional multi-line description to add further provider
information such as processing details for processors and producers,
hosting details for hosts or basic contact information."""

roles: Optional[list[ProviderRole]]
roles: list[ProviderRole] | None
"""Optional roles of the provider. Any of
licensor, producer, processor or host."""

url: Optional[str]
url: str | None
"""Optional homepage on which the provider describes the dataset
and publishes contact information."""

Expand All @@ -56,10 +56,10 @@ class Provider:
def __init__(
self,
name: str,
description: Optional[str] = None,
roles: Optional[list[ProviderRole]] = None,
url: Optional[str] = None,
extra_fields: Optional[dict[str, Any]] = None,
description: str | None = None,
roles: list[ProviderRole] | None = None,
url: str | None = None,
extra_fields: dict[str, Any] | None = None,
):
self.name = name
self.description = description
Expand Down
12 changes: 6 additions & 6 deletions pystac/serialization/common_properties.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Iterable
from typing import Any, Optional, Union, cast
from typing import Any, cast

import pystac
from pystac.cache import CollectionCache
Expand All @@ -9,8 +9,8 @@

def merge_common_properties(
item_dict: dict[str, Any],
collection_cache: Optional[CollectionCache] = None,
json_href: Optional[str] = None,
collection_cache: CollectionCache | None = None,
json_href: str | None = None,
) -> bool:
"""Merges Collection properties into an Item.
Expand All @@ -29,8 +29,8 @@ def merge_common_properties(
"""
properties_merged = False

collection: Optional[Union[pystac.Collection, dict[str, Any]]] = None
collection_href: Optional[str] = None
collection: pystac.Collection | dict[str, Any] | None = None
collection_href: str | None = None

stac_version = item_dict.get("stac_version")

Expand Down Expand Up @@ -79,7 +79,7 @@ def merge_common_properties(
collection = pystac.StacIO.default().read_json(collection_href)

if collection is not None:
collection_props: Optional[dict[str, Any]] = None
collection_props: dict[str, Any] | None = None
if isinstance(collection, pystac.Collection):
collection_id = collection.id
collection_props = collection.extra_fields.get("properties")
Expand Down
3 changes: 2 additions & 1 deletion pystac/serialization/migrate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Callable
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Callable
from typing import TYPE_CHECKING, Any

import pystac
from pystac.serialization.identify import (
Expand Down
3 changes: 2 additions & 1 deletion pystac/stac_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import logging
import os
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any, Callable
from collections.abc import Callable
from typing import TYPE_CHECKING, Any
from urllib.error import HTTPError
from urllib.request import Request, urlopen

Expand Down
3 changes: 1 addition & 2 deletions pystac/stac_object.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from collections.abc import Iterable
from collections.abc import Callable, Iterable
from html import escape
from typing import (
TYPE_CHECKING,
Any,
Callable,
TypeVar,
cast,
)
Expand Down
2 changes: 1 addition & 1 deletion pystac/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import os
import posixpath
import warnings
from collections.abc import Callable
from datetime import datetime, timezone
from enum import Enum
from typing import (
Any,
Callable,
TypeVar,
Union,
cast,
Expand Down
13 changes: 7 additions & 6 deletions pystac/validation/schema_uri_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from abc import ABC, abstractmethod
from collections.abc import Callable
from functools import lru_cache
from typing import Any, Callable, Optional
from typing import Any

import pystac
from pystac.serialization import STACVersionRange
Expand All @@ -17,7 +18,7 @@ def __init__(self) -> None:
@abstractmethod
def get_object_schema_uri(
self, object_type: STACObjectType, stac_version: str
) -> Optional[str]:
) -> str | None:
"""Get the schema URI for the given object type and stac version.
Args:
Expand Down Expand Up @@ -74,7 +75,7 @@ class DefaultSchemaUriMap(SchemaUriMap):
}

@classmethod
def _append_base_uri_if_needed(cls, uri: str, stac_version: str) -> Optional[str]:
def _append_base_uri_if_needed(cls, uri: str, stac_version: str) -> str | None:
# Only append the base URI if it's not already an absolute URI
if "://" not in uri:
for version_range, f in cls.BASE_URIS:
Expand All @@ -89,7 +90,7 @@ def _append_base_uri_if_needed(cls, uri: str, stac_version: str) -> Optional[str

def get_object_schema_uri(
self, object_type: STACObjectType, stac_version: str
) -> Optional[str]:
) -> str | None:
is_latest = stac_version == pystac.get_stac_version()

if object_type not in self.DEFAULT_SCHEMA_MAP:
Expand Down Expand Up @@ -310,7 +311,7 @@ def get_schema_map(cls) -> dict[str, Any]:
@classmethod
def _append_base_uri_if_needed(
cls, uri: str, stac_version: STACVersionID
) -> Optional[str]:
) -> str | None:
# Only append the base URI if it's not already an absolute URI
if "://" not in uri:
for version_range, f in cls.get_base_uris():
Expand All @@ -326,7 +327,7 @@ def _append_base_uri_if_needed(
@classmethod
def get_extension_schema_uri(
cls, extension_id: str, object_type: STACObjectType, stac_version: STACVersionID
) -> Optional[str]:
) -> str | None:
uri = None

is_latest = stac_version == pystac.get_stac_version()
Expand Down
Loading

0 comments on commit ecfc58e

Please sign in to comment.