Skip to content

Commit 1006856

Browse files
committed
Addresses utcnow deprecation.
Improves mypy tox environment.
1 parent d110358 commit 1006856

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ deps =
126126
-e{toxinidir}
127127
mypy
128128
mitogen
129-
commands = mypy -p suitable
129+
commands =
130+
mypy -p suitable --python-version 3.8
131+
mypy -p suitable --python-version 3.9
132+
mypy -p suitable --python-version 3.10
133+
mypy -p suitable --python-version 3.11
134+
mypy -p suitable --python-version 3.12
130135
131136
[testenv:report]
132137
deps =

src/suitable/module_runner.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
from suitable.api import Api
3535

3636

37+
if sys.version_info >= (3, 11):
38+
from datetime import UTC
39+
40+
def utcnow() -> datetime:
41+
return datetime.now(UTC)
42+
else:
43+
utcnow = datetime.utcnow
44+
45+
3746
@contextmanager
3847
def ansible_verbosity(verbosity: int) -> Generator[None, None, None]:
3948
""" Temporarily changes the ansible verbosity. Relies on a single display
@@ -215,7 +224,7 @@ def execute(self, *args: Any, **kwargs: Any) -> RunnerResults:
215224
}
216225

217226
try:
218-
start = datetime.utcnow()
227+
start = utcnow()
219228
task_queue_manager = None
220229
callback = SilentCallbackModule()
221230

@@ -297,7 +306,7 @@ def execute(self, *args: Any, **kwargs: Any) -> RunnerResults:
297306
GlobalCLIArgs)
298307
GlobalCLIArgs._Singleton__instance = None
299308

300-
log.debug(f'took {datetime.utcnow() - start} to complete')
309+
log.debug(f'took {utcnow() - start} to complete')
301310

302311
return self.evaluate_results(callback)
303312

0 commit comments

Comments
 (0)