Skip to content

Commit

Permalink
Remove 3.8 syntax (#41)
Browse files Browse the repository at this point in the history
* Add requires line to pyproject.toml.

* Remove typing module in remaining files.

* Fix bug that refactors two incorrect type.

* Change import style for collections.abc.
  • Loading branch information
ChristianGeng authored Nov 13, 2024
1 parent ae5b35c commit b26e916
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 189 deletions.
16 changes: 9 additions & 7 deletions auglib/core/interface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from collections.abc import Sequence
import os
import typing

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -140,10 +142,10 @@ def __init__(
*,
sampling_rate: int = None,
resample: bool = False,
channels: typing.Union[int, typing.Sequence[int]] = None,
channels: int | Sequence[int] = None,
mixdown: bool = False,
keep_nat: bool = False,
num_workers: typing.Optional[int] = 1,
num_workers: int | None = 1,
multiprocessing: bool = False,
seed: int = None,
verbose: bool = False,
Expand Down Expand Up @@ -184,15 +186,15 @@ def short_id(

def augment(
self,
data: typing.Union[pd.Index, pd.Series, pd.DataFrame],
data: pd.Index | pd.Series | pd.DataFrame,
cache_root: str = None,
*,
data_root: str = None,
remove_root: str = None,
modified_only: bool = True,
num_variants: int = 1,
force: bool = False,
) -> typing.Union[pd.Index, pd.Series, pd.DataFrame]:
) -> pd.Index | pd.Series | pd.DataFrame:
r"""Augment an index, column, or table conform to audformat.
Creates ``num_variants`` copies of the segments referenced in the index
Expand Down Expand Up @@ -505,10 +507,10 @@ def _apply_nat_mask(


def _augmented_files(
files: typing.Sequence[str],
files: Sequence[str],
cache_root: str,
remove_root: str = None,
) -> typing.List[str]:
) -> list[str]:
r"""Return destination path for augmented files.
If files contain the same filename several times,
Expand Down
18 changes: 10 additions & 8 deletions auglib/core/observe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from collections.abc import MutableSequence
import random
import typing

import numpy as np

Expand All @@ -13,7 +15,7 @@ class Base(audobject.Object):
"""

def __call__(self) -> typing.Any: # pragma: no cover
def __call__(self) -> object: # pragma: no cover
r"""Observe next value.
Returns:
Expand Down Expand Up @@ -227,7 +229,7 @@ class List(Base):
)
def __init__(
self,
elements: typing.MutableSequence[typing.Any],
elements: MutableSequence[object],
*,
shuffle: bool = False,
draw: bool = False,
Expand All @@ -241,10 +243,10 @@ def __init__(
self._counter = 0
self._iter = False

def _draw(self) -> typing.Any:
def _draw(self) -> object:
return self.elements[random.randint(0, len(self) - 1)]

def _next(self) -> typing.Any:
def _next(self) -> object:
if self.shuffle and self._counter == 0:
random.shuffle(self.elements)
element = self.elements[self._counter]
Expand All @@ -254,7 +256,7 @@ def _next(self) -> typing.Any:
self._iter = False
return element

def __call__(self) -> typing.Any:
def __call__(self) -> object:
r"""Observe next value from list.
Returns:
Expand All @@ -281,8 +283,8 @@ def __next__(self): # noqa: D105


def observe(
x: typing.Union[typing.Any, Base],
) -> typing.Any:
x: object | Base,
) -> object:
r"""Convenient function to observe a value.
Returns ``x()`` if ``x`` is of type :class:`auglib.observe.Base`,
Expand Down
18 changes: 9 additions & 9 deletions auglib/core/resolver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typing
from collections.abc import MutableSequence

import numpy as np

Expand All @@ -10,14 +10,14 @@ class ArrayResolver(audobject.resolver.Base):

def decode(
self,
value: typing.Any,
) -> typing.Any:
value: object,
) -> object:
return value

def encode(
self,
value: typing.Any,
) -> typing.Any:
value: object,
) -> object:
if isinstance(value, np.ndarray):
raise ValueError(
f"Cannot serialize an instance of "
Expand All @@ -37,14 +37,14 @@ class ObservableListResolver(audobject.resolver.Base):

def decode(
self,
value: typing.Any,
) -> typing.Any:
value: object,
) -> object:
return value

def encode(
self,
value: typing.MutableSequence[typing.Any],
) -> typing.Any:
value: MutableSequence[object],
) -> object:
for v in value:
if isinstance(v, np.ndarray):
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions auglib/core/time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import typing
from __future__ import annotations

import pandas as pd

Expand Down Expand Up @@ -43,7 +43,7 @@ class Time(audobject.Object):

def __init__(
self,
value: typing.Union[int, float, observe.Base],
value: int | float | observe.Base,
unit: str,
):
self.value = value
Expand Down
Loading

0 comments on commit b26e916

Please sign in to comment.