Commit 82d2854f authored by Linus Pithan's avatar Linus Pithan
Browse files

add Axis explicitly to _scannable (type) to avoid property evaluation

of Axis during typechecking
parent 410756fe
......@@ -11,14 +11,17 @@ from bliss.common.counter import Counter
from typing import Union, Optional, Tuple, List, Sequence
from bliss.common.protocols import Scannable, CounterContainer
from bliss.common.measurementgroup import MeasurementGroup
from bliss.common.axis import Axis
######### types for typeguard #########
_int = numbers.Integral
_float = numbers.Real
_countable = Counter
_countables = Union[Counter, MeasurementGroup, CounterContainer, Tuple]
_scannable = Scannable
_scannable_or_name = Union[Scannable, str]
_scannable = Union[Axis, Scannable]
# Axis is included explicitly in _scannable as the Scannable protocol evaluates
# all attributes that are part of the protocol during type checking. (py 3.7)
_scannable_or_name = Union[_scannable, str]
_scannable_start_stop_list = List[Tuple[_scannable, _float, _float]]
_position_list = Union[Sequence, numpy.ndarray]
_scannable_position_list = List[Tuple[_scannable, _position_list]]
......@@ -309,7 +309,7 @@ def wid():
print(std_wid())
# @typeguard.typechecked # type checking acually acceses all members ... does not work for 'bad' motor
@typeguard.typechecked
def stm(*axes: _scannable_or_name, read_hw: bool = False):
"""
Displays state information of the given axes
......
from bliss.common.types import _scannable
import typeguard
def test_scannable_type(default_session):
@typeguard.typechecked
def func_with_scannable(axis: _scannable):
return True
bad = default_session.config.get("bad")
bad.controller.bad_position = False
assert func_with_scannable(bad) == True
bad.controller.bad_position = True
assert func_with_scannable(bad) == True
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment