Coverage for install/scipp/_extend_units.py: 18%

11 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-17 01:51 +0000

1from typing import Any 

2 

3from ._scipp.core import Unit as _Unit 

4from .core import Variable, scalar 

5 

6 

7def __rmul(self: _Unit, value: Any) -> Variable: 

8 return scalar(value, unit=self) 

9 

10 

11def __rtruediv(self: _Unit, value: Any) -> Variable: 

12 return scalar(value, unit=self ** (-1)) 

13 

14 

15def extend_units() -> None: 

16 # add magic python methods to Unit class 

17 # it is done here (on python side) because 

18 # there is no proper way to do this in pybind11 

19 _Unit.__rtruediv__ = __rtruediv 

20 _Unit.__rmul__ = __rmul 

21 

22 # forbid numpy to apply ufuncs to unit 

23 # wrong behavior in scalar * unit otherwise 

24 _Unit.__array_ufunc__ = None