Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Upgrade syntax to py310 using pyupgrade #1162

Merged
merged 5 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
- id: pyupgrade
types: [file]
types_or: [python, pyi]
args: [--py38-plus]
args: [--py310-plus]
exclude: "glotaran.model.item"

- repo: https://github.com/MarcoGorelli/absolufy-imports
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
- ♻️🚇 Use GITHUB_OUTPUT instead of set-output in github actions (#1166)
- 🚧 Add pinned version of odfpy to requirements_dev.txt (#1164)
- ♻️ Use validation action and validation as a git submodule (#1165)
- 🧹 Upgrade syntax to py310 using pyupgrade

(changes-0_6_0)=

Expand Down
3 changes: 1 addition & 2 deletions glotaran/builtin/io/yml/test/test_model_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from os.path import abspath
from os.path import dirname
from os.path import join

Expand All @@ -15,7 +14,7 @@
from glotaran.model import Weight
from glotaran.model import ZeroConstraint

THIS_DIR = dirname(abspath(__file__))
THIS_DIR = dirname(__file__)


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions glotaran/builtin/io/yml/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from ruamel.yaml.compat import StringIO

if TYPE_CHECKING:
from collections.abc import Mapping
from collections.abc import Sequence
from typing import Any
from typing import Mapping
from typing import Sequence

from ruamel.yaml.nodes import ScalarNode
from ruamel.yaml.representer import BaseRepresenter
Expand Down
3 changes: 1 addition & 2 deletions glotaran/cli/commands/optimize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
import typing

import click

Expand Down Expand Up @@ -53,7 +52,7 @@
@util.signature_analysis
def optimize_cmd(
dataformat: str,
data: typing.List[str],
data: list[str],
out: str,
outformat: str,
nfev: int,
Expand Down
2 changes: 1 addition & 1 deletion glotaran/cli/commands/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import sys
from typing import Iterable
from collections.abc import Iterable

import click
from click import echo
Expand Down
19 changes: 10 additions & 9 deletions glotaran/deprecation/deprecation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import os
import re
import sys
from collections.abc import Callable
from collections.abc import Hashable
from collections.abc import Mapping
from collections.abc import MutableMapping
from functools import wraps
from importlib import import_module
from importlib.metadata import distribution
from types import ModuleType
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import Hashable
from typing import Mapping
from typing import MutableMapping
from typing import TypeVar
from typing import cast
from warnings import warn
Expand All @@ -26,8 +26,8 @@
) # decorated function or class

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import NoReturn
from typing import Sequence


class OverDueDeprecation(Exception):
Expand Down Expand Up @@ -740,10 +740,11 @@ def deprecate_submodule(

.. # noqa: DAR402
"""
if module_load_overwrite == "":
new_module = import_module(new_module_name)
else:
new_module = import_module(module_load_overwrite)
new_module = (
import_module(module_load_overwrite)
if module_load_overwrite
else import_module(new_module_name)
)

deprecated_module = ModuleType(
deprecated_module_name,
Expand Down
2 changes: 1 addition & 1 deletion glotaran/deprecation/modules/builtin_io_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from glotaran.deprecation import deprecate_dict_entry

if TYPE_CHECKING:
from collections.abc import MutableMapping
from typing import Any
from typing import MutableMapping


def model_spec_deprecations(spec: MutableMapping[Any, Any]) -> None:
Expand Down
6 changes: 3 additions & 3 deletions glotaran/deprecation/modules/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from glotaran.deprecation.deprecation_utils import GlotaranApiDeprecationWarning

if TYPE_CHECKING:
from collections.abc import Callable
from collections.abc import Mapping
from collections.abc import Sequence
from typing import Any
from typing import Callable
from typing import Mapping
from typing import Sequence

from _pytest.recwarn import WarningsRecorder

Expand Down
4 changes: 2 additions & 2 deletions glotaran/deprecation/test/test_deprecation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from glotaran.deprecation.deprecation_utils import warn_deprecated

if TYPE_CHECKING:
from collections.abc import Hashable
from collections.abc import Mapping
from typing import Any
from typing import Hashable
from typing import Mapping

from _pytest.monkeypatch import MonkeyPatch
from _pytest.recwarn import WarningsRecorder
Expand Down
2 changes: 1 addition & 1 deletion glotaran/io/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Callable
from collections.abc import Callable
from typing import Literal
from typing import Union

Expand Down
2 changes: 1 addition & 1 deletion glotaran/io/prepare_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import xarray as xr

if TYPE_CHECKING:
from typing import Hashable
from collections.abc import Hashable


def prepare_time_trace_dataset(
Expand Down
2 changes: 1 addition & 1 deletion glotaran/model/dataset_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from __future__ import annotations

from collections.abc import Generator
from typing import TYPE_CHECKING
from typing import Generator

import xarray as xr

Expand Down
2 changes: 1 addition & 1 deletion glotaran/model/megacomplex.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""This module contains the megacomplex."""
from __future__ import annotations

from collections.abc import Callable
from typing import TYPE_CHECKING
from typing import Callable
from typing import ClassVar

import numpy as np
Expand Down
8 changes: 4 additions & 4 deletions glotaran/model/model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""This module contains the model."""
from __future__ import annotations

from collections.abc import Callable
from collections.abc import Generator
from collections.abc import Mapping
from typing import Any
from typing import Callable
from typing import ClassVar
from typing import Generator
from typing import Mapping
from uuid import uuid4

from attr import asdict
Expand Down Expand Up @@ -276,7 +276,7 @@ def create_class_from_megacomplexes(
dataset_types |= {
dataset_model_type,
}
attributes.update(_create_attributes_for_item(megacomplex))
attributes |= _create_attributes_for_item(megacomplex)

dataset_type = (
DatasetModel
Expand Down
2 changes: 1 addition & 1 deletion glotaran/parameter/parameters.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""The parameters class."""
from __future__ import annotations

from collections.abc import Generator
from textwrap import indent
from typing import TYPE_CHECKING
from typing import Any
from typing import Generator

import asteval
import numpy as np
Expand Down
9 changes: 4 additions & 5 deletions glotaran/plugin_system/base_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
from warnings import warn

if TYPE_CHECKING:
from collections.abc import Callable
from collections.abc import MutableMapping
from collections.abc import Sequence
from typing import Any
from typing import Callable
from typing import MutableMapping
from typing import Sequence
from typing import Type
from typing import TypeVar

from glotaran.io.interface import DataIoInterface
from glotaran.io.interface import ProjectIoInterface
from glotaran.model.megacomplex import Megacomplex

_PluginType = TypeVar("_PluginType", Type[Megacomplex], DataIoInterface, ProjectIoInterface)
_PluginType = TypeVar("_PluginType", type[Megacomplex], DataIoInterface, ProjectIoInterface)
_PluginInstantiableType = TypeVar(
"_PluginInstantiableType", DataIoInterface, ProjectIoInterface
)
Expand Down
2 changes: 1 addition & 1 deletion glotaran/plugin_system/data_io_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
from glotaran.utils.ipython import MarkdownStr

if TYPE_CHECKING:
from collections.abc import Callable
from typing import Any
from typing import Callable
from typing import Literal

from glotaran.io.interface import DataLoader
Expand Down
6 changes: 3 additions & 3 deletions glotaran/plugin_system/io_plugin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from __future__ import annotations

import os
from collections.abc import Callable
from functools import partial
from functools import wraps
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import TypeVar
from typing import cast

DecoratedFunc = TypeVar("DecoratedFunc", bound=Callable[..., Any]) # decorated function

if TYPE_CHECKING:
from typing import Iterable
from typing import Iterator
from collections.abc import Iterable
from collections.abc import Iterator

from glotaran.typing import StrOrPath

Expand Down
2 changes: 1 addition & 1 deletion glotaran/plugin_system/project_io_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
from glotaran.utils.ipython import MarkdownStr

if TYPE_CHECKING:
from collections.abc import Callable
from typing import Any
from typing import Callable
from typing import Literal

from glotaran.model import Model
Expand Down
5 changes: 2 additions & 3 deletions glotaran/plugin_system/test/test_base_registry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

from collections.abc import MutableMapping
from copy import copy
from typing import TYPE_CHECKING
from typing import MutableMapping
from typing import Type
from typing import cast
from warnings import warn

Expand Down Expand Up @@ -66,7 +65,7 @@ def some_method(self):
mock_registry_project_io = cast(
MutableMapping[str, ProjectIoInterface], copy(mock_registry_data_io)
)
mock_registry_model = cast(MutableMapping[str, Type[Megacomplex]], copy(mock_registry_data_io))
mock_registry_model = cast(MutableMapping[str, type[Megacomplex]], copy(mock_registry_data_io))


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
from glotaran.plugin_system.project_io_registration import show_project_io_method_help

if TYPE_CHECKING:
from collections.abc import Callable
from typing import Any
from typing import Callable

from _pytest.capture import CaptureFixture
from _pytest.monkeypatch import MonkeyPatch
Expand Down
2 changes: 1 addition & 1 deletion glotaran/project/dataclass_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from glotaran.utils.io import relative_posix_path

if TYPE_CHECKING:
from collections.abc import Callable
from typing import Any
from typing import Callable
from typing import TypeVar

from glotaran.typing.protocols import FileLoadable
Expand Down
2 changes: 1 addition & 1 deletion glotaran/project/generators/generator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""The glotaran generator module."""
from __future__ import annotations

from collections.abc import Callable
from typing import Any
from typing import Callable
from typing import TypedDict
from typing import cast

Expand Down
2 changes: 1 addition & 1 deletion glotaran/project/project_registry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""The glotaran registry module."""
from __future__ import annotations

from collections.abc import Callable
from pathlib import Path
from typing import Any
from typing import Callable

from glotaran.utils.ipython import MarkdownStr

Expand Down
7 changes: 3 additions & 4 deletions glotaran/project/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from dataclasses import replace
from typing import TYPE_CHECKING
from typing import Any
from typing import List
from typing import cast

import numpy as np
Expand All @@ -32,8 +31,8 @@

if TYPE_CHECKING:

from typing import Callable
from typing import Mapping
from collections.abc import Callable
from collections.abc import Mapping

from glotaran.typing import StrOrPath

Expand Down Expand Up @@ -285,7 +284,7 @@ def save(
Paths to all the saved files.
"""
return cast(
List[str],
list[str],
save_result(
result_path=path,
result=self,
Expand Down
4 changes: 2 additions & 2 deletions glotaran/project/scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

if TYPE_CHECKING:

from typing import Callable
from collections.abc import Callable
from collections.abc import Mapping
from typing import Literal
from typing import Mapping

import xarray as xr

Expand Down
Loading