Skip to content

Commit

Permalink
Make type hints work for pyuff_ustb objects
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusdk committed Sep 14, 2023
1 parent d43e790 commit 54fbb69
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description = "An implementation of USTB's ultrasound file format (UFF) in Pytho
name = "pyuff_ustb"
readme = "README.md"
requires-python = ">=3.9"
version = "2.0.2"
version = "2.0.3"

[project.urls]
"Bug Tracker" = "https://github.com/magnusdk/pyuff_ustb/issues"
Expand Down
2 changes: 1 addition & 1 deletion pyuff_ustb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from pyuff_ustb.objects import *

__all__ = pyuff_ustb.objects.__all__
__version__ = "2.0.2"
__version__ = "2.0.3"
5 changes: 5 additions & 0 deletions pyuff_ustb/objects/apodization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
from pyuff_ustb.objects.wave import Wave
from pyuff_ustb.objects.window import Window

# Make sure properties are treated as properties when type checking
compulsory_property = property
optional_property = property
dependent_property = property


class Apodization(Uff):
""":class:`Uff` class to hold apodization data.
Expand Down
5 changes: 5 additions & 0 deletions pyuff_ustb/objects/beamformed_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
from pyuff_ustb.objects.scans.scan import Scan
from pyuff_ustb.objects.wave import Wave

# Make sure properties are treated as properties when type checking
compulsory_property = property
optional_property = property
dependent_property = property


class BeamformedData(Uff):
""":class:`Uff` class to hold beamformed data.
Expand Down
5 changes: 5 additions & 0 deletions pyuff_ustb/objects/channel_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
from pyuff_ustb.objects.pulse import Pulse
from pyuff_ustb.objects.wave import Wave

# Make sure properties are treated as properties when type checking
compulsory_property = property
optional_property = property
dependent_property = property


class ChannelData(Uff):
""":class:`Uff` class to hold channel data.
Expand Down
8 changes: 8 additions & 0 deletions pyuff_ustb/objects/phantom.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from typing import TYPE_CHECKING

import numpy as np

from pyuff_ustb.objects.uff import Uff, compulsory_property, dependent_property
from pyuff_ustb.readers import LazyArray, LazyScalar

if TYPE_CHECKING:
# Make sure properties are treated as properties when type checking
compulsory_property = property
optional_property = property
dependent_property = property


class Phantom(Uff):
""":class:`Uff` class for a phantom definition.
Expand Down
8 changes: 8 additions & 0 deletions pyuff_ustb/objects/point.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from typing import TYPE_CHECKING

import numpy as np

from pyuff_ustb.objects.uff import Uff, compulsory_property, dependent_property
from pyuff_ustb.readers import LazyScalar

if TYPE_CHECKING:
# Make sure properties are treated as properties when type checking
compulsory_property = property
optional_property = property
dependent_property = property


class Point(Uff):
""":class:`Uff` class to define a point location.
Expand Down
8 changes: 8 additions & 0 deletions pyuff_ustb/objects/pulse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
from typing import TYPE_CHECKING

import numpy as np

from pyuff_ustb.objects.uff import Uff, compulsory_property
from pyuff_ustb.readers import LazyArray, LazyScalar

if TYPE_CHECKING:
# Make sure properties are treated as properties when type checking
compulsory_property = property
optional_property = property
dependent_property = property


class Pulse(Uff):
""":class:`Uff` class for a pulse definition.
Expand Down
19 changes: 18 additions & 1 deletion pyuff_ustb/objects/uff.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import copy
from enum import Enum
from functools import cached_property
from typing import Any, Generic, List, Optional, Sequence, Tuple, TypeVar, Union
from typing import (
TYPE_CHECKING,
Any,
Generic,
List,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)

import h5py
import numpy as np
Expand Down Expand Up @@ -42,6 +52,13 @@ class dependent_property(property):
written to an UFF file."""


if TYPE_CHECKING:
# Make sure properties are treated as properties when type checking
compulsory_property = property
optional_property = property
dependent_property = property


class Uff:
"""The base class of all UFF objects.
Expand Down
5 changes: 5 additions & 0 deletions pyuff_ustb/objects/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
from pyuff_ustb.objects.probes.probe import Probe
from pyuff_ustb.objects.wavefront import Wavefront

# Make sure properties are treated as properties when type checking
compulsory_property = property
optional_property = property
dependent_property = property


class Wave(Uff):
""":class:`Uff` class that describes a transmitted wave.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="pyuff_ustb",
version="2.0.2",
version="2.0.3",
author_email="magnus.kvalevag@ntnu.no",
packages=find_packages(),
install_requires=["numpy", "h5py"],
Expand Down

0 comments on commit 54fbb69

Please sign in to comment.