From 18c03fd9556fc55f589a8e0a2b2901aa7d8bfca1 Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Wed, 20 Nov 2024 12:37:18 +0100 Subject: [PATCH] Import certain types from collections.abc Import of these from `typing` is deprecated from Python 3.9. --- message_ix/core.py | 3 ++- message_ix/macro.py | 12 ++---------- message_ix/models.py | 3 ++- message_ix/report/__init__.py | 3 ++- message_ix/report/operator.py | 8 ++------ message_ix/testing/__init__.py | 3 ++- message_ix/tests/report/test_operator.py | 3 ++- .../tests/test_feature_vintage_and_active_years.py | 3 ++- 8 files changed, 16 insertions(+), 22 deletions(-) diff --git a/message_ix/core.py b/message_ix/core.py index 40b10d985..c6840c6b3 100755 --- a/message_ix/core.py +++ b/message_ix/core.py @@ -1,8 +1,9 @@ import logging import os +from collections.abc import Iterable, Mapping, Sequence from functools import lru_cache, partial from itertools import chain, product, zip_longest -from typing import Iterable, Mapping, Optional, Sequence, Union +from typing import Optional, Union from warnings import warn import ixmp diff --git a/message_ix/macro.py b/message_ix/macro.py index 89dfc0112..6946f5e8a 100644 --- a/message_ix/macro.py +++ b/message_ix/macro.py @@ -1,19 +1,11 @@ import logging import os +from collections.abc import Collection, Hashable, Iterable, Mapping, MutableMapping from dataclasses import dataclass from functools import partial from operator import itemgetter, mul from pathlib import Path -from typing import ( - TYPE_CHECKING, - Collection, - Hashable, - Iterable, - Mapping, - MutableMapping, - Optional, - Union, -) +from typing import TYPE_CHECKING, Optional, Union import numpy as np import pandas as pd diff --git a/message_ix/models.py b/message_ix/models.py index 846fa12f4..e1567d316 100644 --- a/message_ix/models.py +++ b/message_ix/models.py @@ -1,10 +1,11 @@ import logging from collections import ChainMap +from collections.abc import Mapping, MutableMapping from copy import copy from dataclasses import InitVar, dataclass, field from functools import partial from pathlib import Path -from typing import Mapping, MutableMapping, Optional +from typing import Optional from warnings import warn import ixmp.model.gams diff --git a/message_ix/report/__init__.py b/message_ix/report/__init__.py index 1c3969617..5e17d7744 100644 --- a/message_ix/report/__init__.py +++ b/message_ix/report/__init__.py @@ -1,7 +1,8 @@ import logging +from collections.abc import Mapping from functools import lru_cache, partial from operator import itemgetter -from typing import TYPE_CHECKING, Mapping, Union, cast +from typing import TYPE_CHECKING, Union, cast from genno.operator import broadcast_map from ixmp.report import ( diff --git a/message_ix/report/operator.py b/message_ix/report/operator.py index 916b8c3b2..36df38ea9 100644 --- a/message_ix/report/operator.py +++ b/message_ix/report/operator.py @@ -1,9 +1,5 @@ -from typing import ( - TYPE_CHECKING, - Literal, - Mapping, - overload, -) +from collections.abc import Mapping +from typing import TYPE_CHECKING, Literal, overload import pandas as pd diff --git a/message_ix/testing/__init__.py b/message_ix/testing/__init__.py index ec4f81a4b..d80692a29 100644 --- a/message_ix/testing/__init__.py +++ b/message_ix/testing/__init__.py @@ -1,8 +1,9 @@ import io import os +from collections.abc import Generator from itertools import product from pathlib import Path -from typing import TYPE_CHECKING, Generator, Optional, Union +from typing import TYPE_CHECKING, Optional, Union import numpy as np import pandas as pd diff --git a/message_ix/tests/report/test_operator.py b/message_ix/tests/report/test_operator.py index 98f9cd3ad..c4e5146ca 100644 --- a/message_ix/tests/report/test_operator.py +++ b/message_ix/tests/report/test_operator.py @@ -1,5 +1,6 @@ +from collections.abc import Mapping from functools import partial -from typing import Any, Mapping +from typing import Any import matplotlib import pandas as pd diff --git a/message_ix/tests/test_feature_vintage_and_active_years.py b/message_ix/tests/test_feature_vintage_and_active_years.py index 7a1f080bb..e47605d0e 100644 --- a/message_ix/tests/test_feature_vintage_and_active_years.py +++ b/message_ix/tests/test_feature_vintage_and_active_years.py @@ -1,5 +1,6 @@ +from collections.abc import Sequence from functools import lru_cache -from typing import Optional, Sequence +from typing import Optional import numpy as np import pandas as pd