Skip to content

Commit 4a4d5a8

Browse files
committed
Add ruff lint rule - UP
1 parent 9c9c6e4 commit 4a4d5a8

File tree

12 files changed

+58
-59
lines changed

12 files changed

+58
-59
lines changed

packages/smithy-core/src/smithy_core/documents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _wrap_map(self, value: Mapping[str, DocumentValue]) -> dict[str, "Document"]
230230
member_schema = self._schema.members["value"]
231231
return {k: self._new_document(v, member_schema) for k, v in value.items()}
232232

233-
result: dict[str, "Document"] = {}
233+
result: dict[str, Document] = {}
234234
for k, v in value.items():
235235
result[k] = self._new_document(v, self._schema.members[k])
236236
return result

packages/smithy-core/src/smithy_core/identity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3-
from datetime import datetime, timezone
3+
from datetime import UTC, datetime
44

55
from .interfaces import identity as identity_interface
66
from .utils import ensure_utc
@@ -28,4 +28,4 @@ def is_expired(self) -> bool:
2828
"""Whether the identity is expired."""
2929
if self.expiration is None:
3030
return False
31-
return datetime.now(tz=timezone.utc) >= self.expiration
31+
return datetime.now(tz=UTC) >= self.expiration

packages/smithy-core/src/smithy_core/schemas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(
6767

6868
if members:
6969
if isinstance(members, list):
70-
m: dict[str, "Schema"] = {}
70+
m: dict[str, Schema] = {}
7171
for member in members:
7272
m[member.expect_member_name()] = member
7373
members = m
@@ -140,7 +140,7 @@ def collection(
140140
constructor, this is a dict of member names to a simplified dict containing
141141
only ``traits`` and a ``target``. Member schemas will be generated from this.
142142
"""
143-
struct_members: dict[str, "Schema"] = {}
143+
struct_members: dict[str, Schema] = {}
144144
if members:
145145
for k in members.keys():
146146
struct_members[k] = cls.member(

packages/smithy-core/src/smithy_core/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from datetime import datetime
66
from email.utils import format_datetime, parsedate_to_datetime
77
from enum import Enum
8-
from typing import Any, TypeAlias
8+
from typing import Any
99

1010
from .exceptions import ExpectationNotMetException
1111
from .utils import (
@@ -16,7 +16,7 @@
1616
serialize_rfc3339,
1717
)
1818

19-
Document: TypeAlias = (
19+
type Document = (
2020
Mapping[str, "Document"] | Sequence["Document"] | str | int | float | bool | None
2121
)
2222

packages/smithy-core/src/smithy_core/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
import re
4-
from datetime import datetime, timedelta, timezone
4+
from datetime import UTC, datetime, timedelta
55
from decimal import Decimal
66
from math import isinf, isnan
77
from types import UnionType
@@ -24,9 +24,9 @@ def ensure_utc(value: datetime) -> datetime:
2424
:returns: A UTC timezone-aware equivalent datetime.
2525
"""
2626
if value.tzinfo is None:
27-
return value.replace(tzinfo=timezone.utc)
27+
return value.replace(tzinfo=UTC)
2828
else:
29-
return value.astimezone(timezone.utc)
29+
return value.astimezone(UTC)
3030

3131

3232
# Python is way more permissive on value of non-numerical floats than Smithy is, so we
@@ -61,9 +61,9 @@ def epoch_seconds_to_datetime(value: int | float) -> datetime:
6161
to years from 1970 through 2038." This affects 32-bit systems.
6262
"""
6363
try:
64-
return datetime.fromtimestamp(value, tz=timezone.utc)
64+
return datetime.fromtimestamp(value, tz=UTC)
6565
except OverflowError:
66-
epoch_zero = datetime(1970, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
66+
epoch_zero = datetime(1970, 1, 1, 0, 0, 0, tzinfo=UTC)
6767
return epoch_zero + timedelta(seconds=value)
6868

6969

packages/smithy-core/tests/unit/test_identity.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
3-
from datetime import datetime, timedelta, timezone
3+
from datetime import UTC, datetime, timedelta, timezone
44

55
import pytest
66
from freezegun import freeze_time
@@ -13,7 +13,7 @@
1313
None,
1414
timezone(timedelta(hours=3)),
1515
timezone(timedelta(hours=-3)),
16-
timezone.utc,
16+
UTC,
1717
timezone(timedelta(hours=0)),
1818
timezone(timedelta(hours=0, minutes=30)),
1919
timezone(timedelta(hours=0, minutes=-30)),
@@ -23,28 +23,28 @@ def test_expiration_timezone(time_zone: timezone) -> None:
2323
expiration = datetime.now(tz=time_zone)
2424
identity = Identity(expiration=expiration)
2525
assert identity.expiration is not None
26-
assert identity.expiration.tzinfo == timezone.utc
26+
assert identity.expiration.tzinfo == UTC
2727

2828

2929
@pytest.mark.parametrize(
3030
"identity, expected_expired",
3131
[
3232
(
3333
Identity(
34-
expiration=datetime(year=2023, month=1, day=1, tzinfo=timezone.utc),
34+
expiration=datetime(year=2023, month=1, day=1, tzinfo=UTC),
3535
),
3636
True,
3737
),
3838
(Identity(), False),
3939
(
4040
Identity(
41-
expiration=datetime(year=2023, month=1, day=2, tzinfo=timezone.utc),
41+
expiration=datetime(year=2023, month=1, day=2, tzinfo=UTC),
4242
),
4343
False,
4444
),
4545
(
4646
Identity(
47-
expiration=datetime(year=2022, month=12, day=31, tzinfo=timezone.utc),
47+
expiration=datetime(year=2022, month=12, day=31, tzinfo=UTC),
4848
),
4949
True,
5050
),

packages/smithy-core/tests/unit/test_types.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# pyright: reportPrivateUsage=false
5-
from datetime import datetime, timezone
5+
from datetime import UTC, datetime
66

77
import pytest
88
from smithy_core.exceptions import ExpectationNotMetException
@@ -67,57 +67,57 @@ def test_blob_from_json_immediately_caches() -> None:
6767
(
6868
TimestampFormat.DATE_TIME,
6969
"2017-01-01T00:00:00Z",
70-
datetime(2017, 1, 1, tzinfo=timezone.utc),
70+
datetime(2017, 1, 1, tzinfo=UTC),
7171
),
7272
(
7373
TimestampFormat.EPOCH_SECONDS,
7474
1483228800,
75-
datetime(2017, 1, 1, tzinfo=timezone.utc),
75+
datetime(2017, 1, 1, tzinfo=UTC),
7676
),
7777
(
7878
TimestampFormat.HTTP_DATE,
7979
"Sun, 01 Jan 2017 00:00:00 GMT",
80-
datetime(2017, 1, 1, tzinfo=timezone.utc),
80+
datetime(2017, 1, 1, tzinfo=UTC),
8181
),
8282
(
8383
TimestampFormat.DATE_TIME,
8484
"2017-01-01T00:00:00.000001Z",
85-
datetime(2017, 1, 1, microsecond=1, tzinfo=timezone.utc),
85+
datetime(2017, 1, 1, microsecond=1, tzinfo=UTC),
8686
),
8787
(
8888
TimestampFormat.EPOCH_SECONDS,
8989
1483228800.000001,
90-
datetime(2017, 1, 1, microsecond=1, tzinfo=timezone.utc),
90+
datetime(2017, 1, 1, microsecond=1, tzinfo=UTC),
9191
),
9292
(
9393
TimestampFormat.DATE_TIME,
9494
"1969-12-31T23:59:59Z",
95-
datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
95+
datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC),
9696
),
9797
(
9898
TimestampFormat.EPOCH_SECONDS,
9999
-1,
100-
datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
100+
datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC),
101101
),
102102
(
103103
TimestampFormat.HTTP_DATE,
104104
"Wed, 31 Dec 1969 23:59:59 GMT",
105-
datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
105+
datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC),
106106
),
107107
(
108108
TimestampFormat.DATE_TIME,
109109
"2038-01-19T03:14:08Z",
110-
datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc),
110+
datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC),
111111
),
112112
(
113113
TimestampFormat.EPOCH_SECONDS,
114114
2147483648,
115-
datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc),
115+
datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC),
116116
),
117117
(
118118
TimestampFormat.HTTP_DATE,
119119
"Tue, 19 Jan 2038 03:14:08 GMT",
120-
datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc),
120+
datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC),
121121
),
122122
]
123123

@@ -127,22 +127,22 @@ def test_blob_from_json_immediately_caches() -> None:
127127
(
128128
TimestampFormat.EPOCH_SECONDS,
129129
"1483228800",
130-
datetime(2017, 1, 1, tzinfo=timezone.utc),
130+
datetime(2017, 1, 1, tzinfo=UTC),
131131
),
132132
(
133133
TimestampFormat.EPOCH_SECONDS,
134134
"1483228800.000001",
135-
datetime(2017, 1, 1, microsecond=1, tzinfo=timezone.utc),
135+
datetime(2017, 1, 1, microsecond=1, tzinfo=UTC),
136136
),
137137
(
138138
TimestampFormat.EPOCH_SECONDS,
139139
"-1",
140-
datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
140+
datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC),
141141
),
142142
(
143143
TimestampFormat.EPOCH_SECONDS,
144144
"2147483648",
145-
datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc),
145+
datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC),
146146
),
147147
]
148148
TIMESTAMP_FORMAT_DESERIALIZATION_CASES.extend(TIMESTAMP_FORMAT_SERIALIZATION_CASES)

packages/smithy-core/tests/unit/test_utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# mypy: allow-untyped-defs
55
# mypy: allow-incomplete-defs
66

7-
from datetime import datetime, timedelta, timezone
7+
from datetime import UTC, datetime, timedelta, timezone
88
from decimal import Decimal
99
from math import isnan
1010
from typing import Any, NamedTuple
@@ -30,14 +30,14 @@
3030
@pytest.mark.parametrize(
3131
"given, expected",
3232
[
33-
(datetime(2017, 1, 1), datetime(2017, 1, 1, tzinfo=timezone.utc)),
33+
(datetime(2017, 1, 1), datetime(2017, 1, 1, tzinfo=UTC)),
3434
(
35-
datetime(2017, 1, 1, tzinfo=timezone.utc),
36-
datetime(2017, 1, 1, tzinfo=timezone.utc),
35+
datetime(2017, 1, 1, tzinfo=UTC),
36+
datetime(2017, 1, 1, tzinfo=UTC),
3737
),
3838
(
3939
datetime(2017, 1, 1, tzinfo=timezone(timedelta(hours=1))),
40-
datetime(2016, 12, 31, 23, tzinfo=timezone.utc),
40+
datetime(2016, 12, 31, 23, tzinfo=UTC),
4141
),
4242
],
4343
)
@@ -199,27 +199,27 @@ class DateTimeTestcase(NamedTuple):
199199

200200
DATETIME_TEST_CASES: list[DateTimeTestcase] = [
201201
DateTimeTestcase(
202-
dt_object=datetime(2017, 1, 1, tzinfo=timezone.utc),
202+
dt_object=datetime(2017, 1, 1, tzinfo=UTC),
203203
rfc3339_str="2017-01-01T00:00:00Z",
204204
epoch_seconds_num=1483228800,
205205
epoch_seconds_str="1483228800",
206206
),
207207
DateTimeTestcase(
208-
dt_object=datetime(2017, 1, 1, microsecond=1, tzinfo=timezone.utc),
208+
dt_object=datetime(2017, 1, 1, microsecond=1, tzinfo=UTC),
209209
rfc3339_str="2017-01-01T00:00:00.000001Z",
210210
epoch_seconds_num=1483228800.000001,
211211
epoch_seconds_str="1483228800.000001",
212212
),
213213
DateTimeTestcase(
214-
dt_object=datetime(1969, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
214+
dt_object=datetime(1969, 12, 31, 23, 59, 59, tzinfo=UTC),
215215
rfc3339_str="1969-12-31T23:59:59Z",
216216
epoch_seconds_num=-1,
217217
epoch_seconds_str="-1",
218218
),
219219
# The first second affected by the Year 2038 problem where fromtimestamp raises an
220220
# OverflowError on 32-bit systems for dates beyond 2038-01-19 03:14:07 UTC.
221221
DateTimeTestcase(
222-
dt_object=datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc),
222+
dt_object=datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC),
223223
rfc3339_str="2038-01-19T03:14:08Z",
224224
epoch_seconds_num=2147483648,
225225
epoch_seconds_str="2147483648",
@@ -269,7 +269,7 @@ def test_epoch_seconds_to_datetime_with_overflow_error(monkeypatch): # type: ig
269269
datetime_mock = Mock(wraps=datetime)
270270
datetime_mock.fromtimestamp = Mock(side_effect=OverflowError())
271271
monkeypatch.setattr("smithy_core.utils.datetime", datetime_mock) # type: ignore
272-
dt_object = datetime(2038, 1, 19, 3, 14, 8, tzinfo=timezone.utc)
272+
dt_object = datetime(2038, 1, 19, 3, 14, 8, tzinfo=UTC)
273273
assert epoch_seconds_to_datetime(2147483648) == dt_object
274274

275275

packages/smithy-http/src/smithy_http/aio/crt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _initialize_default_loop(self) -> "crt_io.ClientBootstrap":
5757
class AWSCRTHTTPResponse(http_aio_interfaces.HTTPResponse):
5858
def __init__(self) -> None:
5959
_assert_crt()
60-
self._stream: "crt_http.HttpClientStream | None" = None
60+
self._stream: crt_http.HttpClientStream | None = None
6161
self._status_code_future: Future[int] = Future()
6262
self._headers_future: Future[Fields] = Future()
6363
self._chunk_futures: list[Future[bytes]] = []

packages/smithy-json/src/smithy_json/_private/documents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _wrap_map(self, value: Mapping[str, DocumentValue]) -> dict[str, "Document"]
121121
if self._schema.shape_type not in (ShapeType.STRUCTURE, ShapeType.UNION):
122122
return super()._wrap_map(value)
123123

124-
result: dict[str, "Document"] = {}
124+
result: dict[str, Document] = {}
125125
for k, v in value.items():
126126
member_name = self._json_names.get(k, k)
127127
result[member_name] = self._new_document(

0 commit comments

Comments
 (0)