Skip to content

Commit dbae554

Browse files
nidaqmx: Update to released hightime/nitypes and fix mypy errors (#861)
* chore(deps): update python packages to v1 * pyproject.toml: Stop using deprecated NumPy mypy plugin * pyproject.toml: Remove ignore_missing_imports for hightime * handwritten: Fix most mypy errors for _time.py * tests: Fix mypy errors for _is_timestamp_close_to_now --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent 8967417 commit dbae554

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

generated/nidaqmx/_time.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from datetime import datetime as std_datetime, timezone, tzinfo as dt_tzinfo
3+
from datetime import timezone, tzinfo as dt_tzinfo
44
from zoneinfo import ZoneInfo
55

66
from hightime import datetime as ht_datetime
@@ -9,8 +9,8 @@
99

1010
# theoretically the same as astimezone(), but with support for dates before 1970
1111
def _convert_to_desired_timezone(
12-
expected_time_utc: std_datetime | ht_datetime, tzinfo: dt_tzinfo | None = None
13-
) -> std_datetime | ht_datetime:
12+
expected_time_utc: ht_datetime, tzinfo: dt_tzinfo | None = None
13+
) -> ht_datetime:
1414
# if timezone matches, no need to do conversion
1515
if expected_time_utc.tzinfo is tzinfo:
1616
return expected_time_utc
@@ -23,12 +23,13 @@ def _convert_to_desired_timezone(
2323
if isinstance(tzinfo, ZoneInfo):
2424
localized_time = expected_time_utc.replace(tzinfo=tzinfo)
2525
desired_expected_time = tzinfo.fromutc(localized_time)
26-
return desired_expected_time
26+
return desired_expected_time # type: ignore[return-value] # https://github.com/ni/nidaqmx-python/issues/860
2727

2828
# if the tzinfo passed in is a timedelta function, then we don't need to consider daylight savings # noqa: W505 - doc line too long (102 > 100 characters) (auto-generated noqa)
2929
elif tzinfo.utcoffset(None) is not None:
3030
current_time_utc = ht_datetime.now(timezone.utc)
3131
desired_timezone_offset = current_time_utc.astimezone(tz=tzinfo).utcoffset()
32+
assert desired_timezone_offset is not None
3233
desired_expected_time = expected_time_utc + desired_timezone_offset
3334
new_datetime = desired_expected_time.replace(tzinfo=tzinfo)
3435
return new_datetime

poetry.lock

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ build-backend = "poetry.core.masonry.api"
169169
files = "generated/,tests/"
170170
check_untyped_defs = true
171171
namespace_packages = true
172-
plugins = "numpy.typing.mypy_plugin"
173172
warn_redundant_casts = true
174173
warn_unreachable = true
175174
warn_unused_configs = true
@@ -182,8 +181,6 @@ module = [
182181
# https://github.com/briancurtin/deprecation/issues/56 - Add type information (PEP 561)
183182
"deprecation.*",
184183
"grpc.experimental.*",
185-
# https://github.com/ni/hightime/issues/4 - Add type annotations
186-
"hightime.*",
187184
"importlib_metadata",
188185
"mako.*",
189186
"nidaqmx.*",

src/handwritten/_time.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from datetime import datetime as std_datetime, timezone, tzinfo as dt_tzinfo
3+
from datetime import timezone, tzinfo as dt_tzinfo
44
from zoneinfo import ZoneInfo
55

66
from hightime import datetime as ht_datetime
@@ -9,8 +9,8 @@
99

1010
# theoretically the same as astimezone(), but with support for dates before 1970
1111
def _convert_to_desired_timezone(
12-
expected_time_utc: std_datetime | ht_datetime, tzinfo: dt_tzinfo | None = None
13-
) -> std_datetime | ht_datetime:
12+
expected_time_utc: ht_datetime, tzinfo: dt_tzinfo | None = None
13+
) -> ht_datetime:
1414
# if timezone matches, no need to do conversion
1515
if expected_time_utc.tzinfo is tzinfo:
1616
return expected_time_utc
@@ -23,12 +23,13 @@ def _convert_to_desired_timezone(
2323
if isinstance(tzinfo, ZoneInfo):
2424
localized_time = expected_time_utc.replace(tzinfo=tzinfo)
2525
desired_expected_time = tzinfo.fromutc(localized_time)
26-
return desired_expected_time
26+
return desired_expected_time # type: ignore[return-value] # https://github.com/ni/nidaqmx-python/issues/860
2727

2828
# if the tzinfo passed in is a timedelta function, then we don't need to consider daylight savings # noqa: W505 - doc line too long (102 > 100 characters) (auto-generated noqa)
2929
elif tzinfo.utcoffset(None) is not None:
3030
current_time_utc = ht_datetime.now(timezone.utc)
3131
desired_timezone_offset = current_time_utc.astimezone(tz=tzinfo).utcoffset()
32+
assert desired_timezone_offset is not None
3233
desired_expected_time = expected_time_utc + desired_timezone_offset
3334
new_datetime = desired_expected_time.replace(tzinfo=tzinfo)
3435
return new_datetime

tests/component/_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from datetime import timezone
66

77
from hightime import datetime as ht_datetime
8+
from nitypes.time.typing import AnyDateTime
89

910

10-
def _is_timestamp_close_to_now(timestamp: ht_datetime, tolerance_seconds: float = 1.0) -> bool:
11+
def _is_timestamp_close_to_now(timestamp: AnyDateTime, tolerance_seconds: float = 1.0) -> bool:
1112
current_time = ht_datetime.now(timezone.utc)
1213
time_diff = abs((timestamp - current_time).total_seconds())
1314
return time_diff <= tolerance_seconds

0 commit comments

Comments
 (0)