Skip to content

Commit a254f10

Browse files
gadomskijsignell
andauthored
pyupgrade to 3.10 (#1388)
* chore: pyupgrade to 3.10 * chore: update changelog --------- Co-authored-by: Julia Signell <jsignell@gmail.com>
1 parent c44ba70 commit a254f10

25 files changed

+81
-85
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
repos:
55
- repo: https://github.com/asottile/pyupgrade
6-
rev: v3.15.0
6+
rev: v3.17.0
77
hooks:
88
- id: pyupgrade
99
args:
10-
- "--py39-plus"
10+
- "--py310-plus"
1111

1212
- repo: local
1313
hooks:

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Added
66

7-
- Add netCDF to pystac.media_type ([#1386](https://github.com/stac-utils/pystac/pull/1386))
7+
- Add netCDF to pystac.media_type ([#1386](https://github.com/stac-utils/pystac/pull/1386))
88
- Add convenience method for accessing pystac_client ([#1365](https://github.com/stac-utils/pystac/pull/1365))
99

1010
### Changed
@@ -20,7 +20,7 @@
2020

2121
### Removed
2222

23-
- Python 3.9 ([#1384](https://github.com/stac-utils/pystac/pull/1384))
23+
- Python 3.9 ([#1384](https://github.com/stac-utils/pystac/pull/1384), [#1388](https://github.com/stac-utils/pystac/pull/1388))
2424

2525
## [v1.10.1] - 2024-05-03
2626

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test = [
4949
"html5lib~=1.1",
5050
"jinja2<4.0",
5151
"jsonschema~=4.18",
52-
"mypy~=1.2",
52+
"mypy~=1.11",
5353
"orjson~=3.8",
5454
"pre-commit~=3.2",
5555
"pytest-cov~=5.0",
@@ -104,7 +104,7 @@ max-line-length = 88
104104

105105
[tool.ruff]
106106
line-length = 88
107-
select = ["E", "F", "I"]
107+
lint.select = ["E", "F", "I"]
108108

109109
[tool.pytest.ini_options]
110110
filterwarnings = ["error"]

pystac/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
PySTAC is a library for working with SpatioTemporal Asset Catalogs (STACs)
44
"""
5+
56
__all__ = [
67
"__version__",
78
"TemplateError",
@@ -44,7 +45,7 @@
4445

4546
import os
4647
import warnings
47-
from typing import Any, Optional
48+
from typing import Any
4849

4950
from pystac.errors import (
5051
TemplateError,
@@ -136,7 +137,7 @@
136137
)
137138

138139

139-
def read_file(href: HREF, stac_io: Optional[StacIO] = None) -> STACObject:
140+
def read_file(href: HREF, stac_io: StacIO | None = None) -> STACObject:
140141
"""Reads a STAC object from a file.
141142
142143
This method will return either a Catalog, a Collection, or an Item based on what
@@ -168,8 +169,8 @@ def read_file(href: HREF, stac_io: Optional[StacIO] = None) -> STACObject:
168169
def write_file(
169170
obj: STACObject,
170171
include_self_link: bool = True,
171-
dest_href: Optional[HREF] = None,
172-
stac_io: Optional[StacIO] = None,
172+
dest_href: HREF | None = None,
173+
stac_io: StacIO | None = None,
173174
) -> None:
174175
"""Writes a STACObject to a file.
175176
@@ -202,9 +203,9 @@ def write_file(
202203

203204
def read_dict(
204205
d: dict[str, Any],
205-
href: Optional[str] = None,
206-
root: Optional[Catalog] = None,
207-
stac_io: Optional[StacIO] = None,
206+
href: str | None = None,
207+
root: Catalog | None = None,
208+
stac_io: StacIO | None = None,
208209
) -> STACObject:
209210
"""Reads a :class:`~STACObject` or :class:`~ItemCollection` from a JSON-like dict
210211
representing a serialized STAC object.

pystac/catalog.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import os
44
import warnings
5-
from collections.abc import Iterable, Iterator
5+
from collections.abc import Callable, Iterable, Iterator
66
from copy import deepcopy
77
from itertools import chain
88
from typing import (
99
TYPE_CHECKING,
1010
Any,
11-
Callable,
1211
TypeVar,
1312
Union,
1413
cast,

pystac/errors.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Optional, Union
1+
from typing import Any
22

33

44
class TemplateError(Exception):
@@ -28,7 +28,7 @@ def __init__(
2828
self,
2929
bad_dict: dict[str, Any],
3030
expected: type,
31-
extra_message: Optional[str] = "",
31+
extra_message: str | None = "",
3232
):
3333
"""
3434
Construct an exception with an appropriate error message from bad_dict and the
@@ -88,9 +88,7 @@ class RequiredPropertyMissing(Exception):
8888
prop: The property that is missing
8989
"""
9090

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

@@ -109,7 +107,7 @@ class STACValidationError(Exception):
109107
the ``jsonschema.ValidationError``.
110108
"""
111109

112-
def __init__(self, message: str, source: Optional[Any] = None):
110+
def __init__(self, message: str, source: Any | None = None):
113111
super().__init__(message)
114112
self.source = source
115113

pystac/extensions/mgrs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import re
44
from re import Pattern
5-
from typing import Any, Literal, Optional, Union
5+
from typing import Any, Literal, Union
66

77
import pystac
88
from pystac.extensions.base import ExtensionManagementMixin, PropertiesExtension
@@ -132,7 +132,7 @@ def validated_grid_square(v: str) -> str:
132132
return v
133133

134134

135-
def validated_utm_zone(v: Optional[int]) -> Optional[int]:
135+
def validated_utm_zone(v: int | None) -> int | None:
136136
if v is not None and not isinstance(v, int):
137137
raise ValueError("Invalid MGRS utm zone: must be None or int")
138138
if v is not None and v not in UTM_ZONES:
@@ -175,7 +175,7 @@ def apply(
175175
self,
176176
latitude_band: str,
177177
grid_square: str,
178-
utm_zone: Optional[int] = None,
178+
utm_zone: int | None = None,
179179
) -> None:
180180
"""Applies MGRS extension properties to the extended Item.
181181
@@ -189,7 +189,7 @@ def apply(
189189
self.utm_zone = validated_utm_zone(utm_zone)
190190

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

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

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

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

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

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

222222
@classmethod

pystac/extensions/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def get_object_links(self, so: STACObject) -> list[str] | None:
429429

430430

431431
@contextmanager
432-
def ignore_deprecated() -> Generator[None, None, None]:
432+
def ignore_deprecated() -> Generator[None]:
433433
"""Context manager for suppressing the :class:`pystac.DeprecatedWarning`
434434
when creating a deprecated :class:`~pystac.Item` or :class:`~pystac.Collection`
435435
from a dictionary."""

pystac/layout.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import warnings
66
from abc import ABC, abstractmethod
77
from collections import OrderedDict
8+
from collections.abc import Callable
89
from string import Formatter
9-
from typing import TYPE_CHECKING, Any, Callable
10+
from typing import TYPE_CHECKING, Any
1011

1112
import pystac
1213
from pystac.utils import is_file_path

pystac/provider.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from html import escape
2-
from typing import Any, Optional
2+
from typing import Any
33

44
from pystac.html.jinja_env import get_jinja_env
55
from pystac.utils import StringEnum
@@ -36,16 +36,16 @@ class Provider:
3636
name: str
3737
"""The name of the organization or the individual."""
3838

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

44-
roles: Optional[list[ProviderRole]]
44+
roles: list[ProviderRole] | None
4545
"""Optional roles of the provider. Any of
4646
licensor, producer, processor or host."""
4747

48-
url: Optional[str]
48+
url: str | None
4949
"""Optional homepage on which the provider describes the dataset
5050
and publishes contact information."""
5151

@@ -56,10 +56,10 @@ class Provider:
5656
def __init__(
5757
self,
5858
name: str,
59-
description: Optional[str] = None,
60-
roles: Optional[list[ProviderRole]] = None,
61-
url: Optional[str] = None,
62-
extra_fields: Optional[dict[str, Any]] = None,
59+
description: str | None = None,
60+
roles: list[ProviderRole] | None = None,
61+
url: str | None = None,
62+
extra_fields: dict[str, Any] | None = None,
6363
):
6464
self.name = name
6565
self.description = description

0 commit comments

Comments
 (0)