Skip to content

Commit

Permalink
Upgrade typing for tests (via pyupgrade)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwtoews committed Oct 3, 2023
1 parent c6f45f6 commit d8c214b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pickle
import tempfile
import unittest
from typing import Dict, Iterator, Tuple
from typing import Iterator

import numpy as np
import pytest
Expand All @@ -23,7 +23,7 @@ def setUp(self) -> None:

def boxes15_stream(
self, interleaved: bool = True
) -> Iterator[Tuple[int, Tuple[float, float, float, float], int]]:
) -> Iterator[tuple[int, tuple[float, float, float, float], int]]:
boxes15 = np.genfromtxt("boxes_15x15.data")
for i, (minx, miny, maxx, maxy) in enumerate(boxes15):
if interleaved:
Expand Down Expand Up @@ -394,7 +394,7 @@ def setUp(self) -> None:

def boxes15_stream(
self, interleaved: bool = True
) -> Iterator[Tuple[int, Tuple[float, float, float, float], int]]:
) -> Iterator[tuple[int, tuple[float, float, float, float], int]]:
for i, (minx, miny, maxx, maxy) in enumerate(self.boxes15):
if interleaved:
yield (i, (minx, miny, maxx, maxy), 42)
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_interleaving(self) -> None:

def data_gen(
interleaved: bool = True,
) -> Iterator[Tuple[int, Tuple[float, float, float, float], int]]:
) -> Iterator[tuple[int, tuple[float, float, float, float], int]]:
for i, (minx, miny, maxx, maxy) in enumerate(self.boxes15):
if interleaved:
yield (i, (minx, miny, maxx, maxy), 42)
Expand Down Expand Up @@ -590,7 +590,7 @@ def data_gen(

# go through the traversal and see if everything is close
assert all(
all(np.allclose(a, b) for a, b in zip(L, E))
all(np.allclose(a, b) for a, b in zip(L, E)) # type: ignore
for L, E in zip(leaves, expected)
)

Expand Down Expand Up @@ -724,7 +724,7 @@ class TestException(Exception):
pass

def create_index() -> index.Index:
def gen() -> Iterator[Tuple[int, Tuple[int, int, int, int], None]]:
def gen() -> Iterator[tuple[int, tuple[int, int, int, int], None]]:
# insert at least 6 or so before the exception
for i in range(10):
yield (i, (1, 2, 3, 4), None)
Expand Down Expand Up @@ -767,7 +767,7 @@ def destroy(self, returnError):

def clear(self) -> None:
"""Clear all our data"""
self.dict: Dict = {}
self.dict: dict = {}

def loadByteArray(self, page, returnError):
"""Returns the data for page or returns an error"""
Expand Down
26 changes: 13 additions & 13 deletions tests/test_tpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest
from collections import defaultdict, namedtuple
from math import ceil
from typing import Any, Iterator, Optional, Tuple, Union
from typing import Any, Iterator

import numpy as np

Expand All @@ -25,15 +25,15 @@ def getX(self, t: float) -> float:
def getY(self, t: float) -> float:
return self.y + self.y_vel * (t - self.time)

def getXY(self, t: float) -> Tuple[float, float]:
def getXY(self, t: float) -> tuple[float, float]:
return self.getX(t), self.getY(t)

def get_coordinates(
self, t_now: Optional[float] = None
) -> Tuple[
Tuple[float, float, float, float],
Tuple[float, float, float, float],
Union[float, Tuple[float, float]],
self, t_now: float | None = None
) -> tuple[
tuple[float, float, float, float],
tuple[float, float, float, float],
float | tuple[float, float],
]:
return (
(self.x, self.y, self.x, self.y),
Expand All @@ -49,10 +49,10 @@ class QueryCartesian(

def get_coordinates(
self,
) -> Tuple[
Tuple[float, float, float, float],
Tuple[float, float, float, float],
Tuple[float, float],
) -> tuple[
tuple[float, float, float, float],
tuple[float, float, float, float],
tuple[float, float],
]:
return (
(self.x - self.dx, self.y - self.dy, self.x + self.dx, self.y + self.dy),
Expand All @@ -78,9 +78,9 @@ def data_generator(
min_y: int = 0,
max_x: int = 1,
max_y: int = 1,
) -> Iterator[Tuple[str, int, Any]]:
) -> Iterator[tuple[str, int, Any]]:
def create_object(
id_: float, time: float, x: Optional[float] = None, y: Optional[float] = None
id_: float, time: float, x: float | None = None, y: float | None = None
) -> Cartesian:
# Create object with random or defined x, y and random velocity
if x is None:
Expand Down

0 comments on commit d8c214b

Please sign in to comment.