diff --git a/python/snewpy/_model_downloader.py b/python/snewpy/_model_downloader.py index bb7096f3..c2de85a0 100644 --- a/python/snewpy/_model_downloader.py +++ b/python/snewpy/_model_downloader.py @@ -15,7 +15,6 @@ from importlib.resources import open_text from pathlib import Path from tqdm.auto import tqdm -from typing import Optional from snewpy import model_path from snewpy import __version__ as snewpy_version @@ -79,7 +78,7 @@ class FileHandle: path: Path remote: str = None - md5: Optional[str] = None + md5: str | None = None def check(self) -> None: """Check if the given file exists locally and has a correct md5 sum. diff --git a/python/snewpy/flux.py b/python/snewpy/flux.py index 00baec6a..3cdfa918 100644 --- a/python/snewpy/flux.py +++ b/python/snewpy/flux.py @@ -51,7 +51,6 @@ .. autoclass:: Axes """ -from typing import Union, Optional #from snewpy.neutrino import Flavor from snewpy.flavor import FlavorScheme, FlavorMatrix from astropy import units as u @@ -73,8 +72,8 @@ class Axes(IntEnum): energy=2, #Energy dimension @classmethod - def get(cls, value:Union['Axes',int,str])->'Axes': - "convert string,int or Axes value to Axes" + def get(cls, value: 'Axes' | int | str)->'Axes': + "convert string, int or Axes value to Axes" if isinstance(value,str): return cls[value] else: @@ -85,14 +84,14 @@ class _ContainerBase: :noindex: """ unit = None - def __init__(self, + def __init__(self, data: u.Quantity, flavor: list[FlavorScheme], - time: u.Quantity[u.s], + time: u.Quantity[u.s], energy: u.Quantity[u.MeV], *, - integrable_axes: Optional[set[Axes]] = None, - flavor_scheme:Optional[FlavorScheme] = None + integrable_axes: set[Axes] | None = None, + flavor_scheme: FlavorScheme | None = None ): """A container class storing the physical quantity (flux, fluence, rate...), which depends on flavor, time and energy. @@ -204,7 +203,7 @@ def __repr__(self) -> str: ] return f"{self.__class__.__name__} {self.array.shape} [{self.array.unit}]: <{' x '.join(s)}>" - def sum(self, axis: Union[Axes,str])->'Container': + def sum(self, axis: Axes | str)->'Container': """Sum along given axis, producing a Container with the summary quantity. Parameters @@ -249,7 +248,7 @@ def sum(self, axis: Union[Axes,str])->'Container': axes[axis] = axes[axis].take([0,-1]) return Container(array,*axes, integrable_axes = self._integrable_axes.difference({axis})) - def integrate(self, axis:Union[Axes,str], limits:np.ndarray=None)->'Container': + def integrate(self, axis: Axes | str, limits:np.ndarray=None)->'Container': """Integrate along given axis, producing a Container with the integral quantity. Parameters @@ -317,7 +316,7 @@ def integrate(self, axis:Union[Axes,str], limits:np.ndarray=None)->'Container': #choose the proper class return Container(array, *axes, integrable_axes=self._integrable_axes.difference({axis})) - def integrate_or_sum(self, axis:Union[Axes,str])->'Container': + def integrate_or_sum(self, axis: Axes | str)->'Container': if self.can_integrate(axis): return self.integrate(axis) else: diff --git a/python/snewpy/neutrino.py b/python/snewpy/neutrino.py index e5a83bb1..6456fc75 100644 --- a/python/snewpy/neutrino.py +++ b/python/snewpy/neutrino.py @@ -4,7 +4,6 @@ from enum import IntEnum from astropy import units as u from dataclasses import dataclass -from typing import Optional import numpy as np from collections.abc import Mapping from .flavor import ThreeFlavor as Flavor @@ -41,10 +40,10 @@ class MixingParameters3Flavor(Mapping): deltaCP: u.Quantity[u.deg] #square mass difference dm21_2: u.Quantity[u.eV**2] - dm32_2: Optional[u.Quantity] = None - dm31_2: Optional[u.Quantity] = None + dm32_2: u.Quantity | None = None + dm31_2: u.Quantity | None = None #mass ordering - mass_order: Optional[MassHierarchy] = None + mass_order: MassHierarchy | None = None # Note: in IH, the mass splittings are: m3..............m1..m2. def __iter__(self): @@ -124,8 +123,8 @@ class MixingParameters4Flavor(MixingParameters3Flavor): theta34: u.Quantity[u.deg] = 0<