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

Enable Python 3.10+ in pre-commit hooks #422

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ repos:
rev: 24.10.0
hooks:
- id: black
args: [--target-version=py36]

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade
args:
- --py39-plus
- --py310-plus

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
Expand Down
10 changes: 4 additions & 6 deletions ome_zarr/axes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Axes class for validating and transforming axes
"""

from typing import Any, Union
from typing import Any

from .format import CurrentFormat, Format

Expand All @@ -11,7 +11,7 @@
class Axes:
def __init__(
self,
axes: Union[list[str], list[dict[str, str]]],
axes: list[str] | list[dict[str, str]],
fmt: Format = CurrentFormat(),
) -> None:
"""
Expand Down Expand Up @@ -41,15 +41,13 @@ def validate(self) -> None:

def to_list(
self, fmt: Format = CurrentFormat()
) -> Union[list[str], list[dict[str, str]]]:
) -> list[str] | list[dict[str, str]]:
if fmt.version == "0.3":
return self._get_names()
return self.axes

@staticmethod
def _axes_to_dicts(
axes: Union[list[str], list[dict[str, str]]]
) -> list[dict[str, str]]:
def _axes_to_dicts(axes: list[str] | list[dict[str, str]]) -> list[dict[str, str]]:
"""Returns a list of axis dicts with name and type"""
axes_dicts = []
for axis in axes:
Expand Down
3 changes: 1 addition & 2 deletions ome_zarr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import argparse
import logging
import sys
from typing import Union

from .csv import csv_to_zarr
from .data import astronaut, coins, create_zarr
Expand Down Expand Up @@ -81,7 +80,7 @@ def csv_to_labels(args: argparse.Namespace) -> None:
csv_to_zarr(args.csv_path, args.csv_id, args.csv_keys, args.zarr_path, args.zarr_id)


def main(args: Union[list[str], None] = None) -> None:
def main(args: list[str] | None = None) -> None:
"""Run appropriate function with argparse arguments, handling errors."""
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down
9 changes: 4 additions & 5 deletions ome_zarr/csv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import csv
import os
from typing import Union

from zarr.convenience import open as zarr_open

Expand All @@ -13,9 +12,9 @@
COLUMN_TYPES = ["d", "l", "s", "b"]


def parse_csv_value(value: str, col_type: str) -> Union[str, float, int, bool]:
def parse_csv_value(value: str, col_type: str) -> str | float | int | bool:
"""Parse string value from csv, according to COLUMN_TYPES"""
rv: Union[str, float, int, bool] = value
rv: str | float | int | bool = value
try:
if col_type == "d":
rv = float(value)
Expand Down Expand Up @@ -62,7 +61,7 @@ def csv_to_zarr(
csv_columns = None
id_column = None

props_by_id: dict[Union[str, int], dict] = {}
props_by_id: dict[str | int, dict] = {}

with open(csv_path, newline="") as csvfile:
row_reader = csv.reader(csvfile, delimiter=",")
Expand Down Expand Up @@ -90,7 +89,7 @@ def csv_to_zarr(


def dict_to_zarr(
props_to_add: dict[Union[str, int], dict], zarr_path: str, zarr_id: str
props_to_add: dict[str | int, dict], zarr_path: str, zarr_id: str
) -> None:
"""
Add keys:values to the label properties of a ome-zarr Plate or Image.
Expand Down
4 changes: 2 additions & 2 deletions ome_zarr/data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Functions for generating synthetic data."""

from collections.abc import Callable
from random import randrange
from typing import Callable, Optional, Union

import numpy as np
import zarr
Expand Down Expand Up @@ -122,7 +122,7 @@ def create_zarr(
method: Callable[..., tuple[list, list]] = coins,
label_name: str = "coins",
fmt: Format = CurrentFormat(),
chunks: Optional[Union[tuple, list]] = None,
chunks: tuple | list | None = None,
) -> zarr.Group:
"""Generate a synthetic image pyramid with labels."""
pyramid, labels = method()
Expand Down
18 changes: 9 additions & 9 deletions ome_zarr/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from abc import ABC, abstractmethod
from collections.abc import Iterator
from typing import Any, Optional
from typing import Any

from zarr.storage import FSStore

Expand Down Expand Up @@ -67,7 +67,7 @@ def init_store(self, path: str, mode: str = "r") -> FSStore:
def init_channels(self) -> None: # pragma: no cover
raise NotImplementedError()

def _get_metadata_version(self, metadata: dict) -> Optional[str]:
def _get_metadata_version(self, metadata: dict) -> str | None:
"""
Checks the metadata dict for a version

Expand Down Expand Up @@ -105,16 +105,16 @@ def validate_well_dict(
@abstractmethod
def generate_coordinate_transformations(
self, shapes: list[tuple]
) -> Optional[list[list[dict[str, Any]]]]: # pragma: no cover
) -> list[list[dict[str, Any]]] | None: # pragma: no cover
raise NotImplementedError()

@abstractmethod
def validate_coordinate_transformations(
self,
ndim: int,
nlevels: int,
coordinate_transformations: Optional[list[list[dict[str, Any]]]] = None,
) -> Optional[list[list[dict[str, Any]]]]: # pragma: no cover
coordinate_transformations: list[list[dict[str, Any]]] | None = None,
) -> list[list[dict[str, Any]]] | None: # pragma: no cover
raise NotImplementedError()


Expand Down Expand Up @@ -159,14 +159,14 @@ def validate_well_dict(

def generate_coordinate_transformations(
self, shapes: list[tuple]
) -> Optional[list[list[dict[str, Any]]]]:
) -> list[list[dict[str, Any]]] | None:
return None

def validate_coordinate_transformations(
self,
ndim: int,
nlevels: int,
coordinate_transformations: Optional[list[list[dict[str, Any]]]] = None,
coordinate_transformations: list[list[dict[str, Any]]] | None = None,
) -> None:
return None

Expand Down Expand Up @@ -260,7 +260,7 @@ def validate_well_dict(

def generate_coordinate_transformations(
self, shapes: list[tuple]
) -> Optional[list[list[dict[str, Any]]]]:
) -> list[list[dict[str, Any]]] | None:
data_shape = shapes[0]
coordinate_transformations: list[list[dict[str, Any]]] = []
# calculate minimal 'scale' transform based on pyramid dims
Expand All @@ -275,7 +275,7 @@ def validate_coordinate_transformations(
self,
ndim: int,
nlevels: int,
coordinate_transformations: Optional[list[list[dict[str, Any]]]] = None,
coordinate_transformations: list[list[dict[str, Any]]] | None = None,
) -> None:
"""
Validates that a list of dicts contains a 'scale' transformation
Expand Down
7 changes: 3 additions & 4 deletions ome_zarr/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import logging
from pathlib import Path
from typing import Optional, Union
from urllib.parse import urljoin

import dask.array as da
Expand All @@ -29,7 +28,7 @@ class ZarrLocation:

def __init__(
self,
path: Union[Path, str, FSStore],
path: Path | str | FSStore,
mode: str = "r",
fmt: Format = CurrentFormat(),
) -> None:
Expand Down Expand Up @@ -207,8 +206,8 @@ def _ishttp(self) -> bool:


def parse_url(
path: Union[Path, str], mode: str = "r", fmt: Format = CurrentFormat()
) -> Optional[ZarrLocation]:
path: Path | str, mode: str = "r", fmt: Format = CurrentFormat()
) -> ZarrLocation | None:
"""Convert a path string or URL to a ZarrLocation subclass.

:param path: Path to parse.
Expand Down
8 changes: 4 additions & 4 deletions ome_zarr/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def add(
self,
zarr: ZarrLocation,
prepend: bool = False,
visibility: Optional[bool] = None,
visibility: bool | None = None,
plate_labels: bool = False,
) -> "Optional[Node]":
"""Create a child node if this location has not yet been seen.
Expand Down Expand Up @@ -227,7 +227,7 @@ def __init__(self, node: Node) -> None:
LOGGER.warning("no parent found for %s: %s", self, image)

# Metadata: TODO move to a class
colors: dict[Union[int, bool], list[float]] = {}
colors: dict[int | bool, list[float]] = {}
color_list = image_label.get("colors", [])
if color_list:
for color in color_list:
Expand Down Expand Up @@ -352,7 +352,7 @@ def __init__(self, node: Node) -> None:
return # EARLY EXIT

colormaps = []
contrast_limits: Optional[list[Optional[Any]]] = [None for x in channels]
contrast_limits: list[Any | None] | None = [None for x in channels]
names: list[str] = [("channel_%d" % idx) for idx, ch in enumerate(channels)]
visibles: list[bool] = [True for x in channels]

Expand Down Expand Up @@ -496,7 +496,7 @@ def get_pyramid_lazy(self, node: Node) -> None:
# Get the first well...
well_zarr = self.zarr.create(self.well_paths[0])
well_node = Node(well_zarr, node)
well_spec: Optional[Well] = well_node.first(Well)
well_spec: Well | None = well_node.first(Well)
if well_spec is None:
raise Exception("Could not find first well")
self.first_field_path = well_spec.well_data["images"][0]["path"]
Expand Down
4 changes: 2 additions & 2 deletions ome_zarr/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import inspect
import logging
import os
from collections.abc import Iterator, MutableMapping
from collections.abc import Callable, Iterator, MutableMapping
from dataclasses import dataclass
from typing import Any, Callable, Union
from typing import Any, Union

import dask.array as da
import numpy as np
Expand Down
3 changes: 2 additions & 1 deletion ome_zarr/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Definition of complex types for use elsewhere."""

from typing import Any, Callable, Union
from collections.abc import Callable
from typing import Any, Union

LayerData = Union[tuple[Any], tuple[Any, dict], tuple[Any, dict, str]]

Expand Down
Loading
Loading