Skip to content

Commit

Permalink
Use optional type rather than union with None
Browse files Browse the repository at this point in the history
  • Loading branch information
php1ic committed Aug 17, 2024
1 parent 2fb061c commit 5d4b856
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pynch/nubase_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def __init__(self, filename: pathlib.Path, year: int):
super().__init__(self.year)
logging.info(f"Reading {self.filename} from {self.year}")

def _read_halflife_value(self, line: str) -> typing.Union[float, None]:
def _read_halflife_value(self, line: str) -> typing.Optional[float]:
"""Slice the string to get the numerical value or None if it's empty."""
data = line[self.START_HALFLIFEVALUE: self.END_HALFLIFEVALUE].strip()
number = re.sub(r"[<>?~]", "", data)
return float(number) if number else None

def _read_halflife_error(self, line: str) -> typing.Union[float, None]:
def _read_halflife_error(self, line: str) -> typing.Optional[float]:
"""Slice the string to get the numerical value or None if it's empty."""
data = line[self.START_HALFLIFEERROR: self.END_HALFLIFEERROR].strip()
number = re.sub(r"[<>?~a-z]", "", data)
Expand All @@ -48,7 +48,7 @@ def _read_all_halflife_data(self, line: str) -> tuple:
self._read_halflife_error(line)
)

def _read_spin(self, line: str) -> typing.Union[str, None]:
def _read_spin(self, line: str) -> typing.Optional[str]:
"""Extract the spin of the isotope and it's level."""
# 2020 brought in '*' for directly measured. Just remove it for the moment
# TODO parse the spin parity with the new characters
Expand Down

0 comments on commit 5d4b856

Please sign in to comment.