Skip to content

Commit

Permalink
more callback doc fixes, but more work needed to clean up type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewAnnex committed Apr 14, 2020
1 parent 8440e05 commit 9a145bc
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions spiceypy/utils/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def SpiceUDFUNC(f: Callable[[float], float]) -> UDFUNC:
"""
Decorator for wrapping python functions in spice udfunc callback type
:param f: function that has one argument of type float, and returns a float
:type f: builtins.function
:return: wrapped udfunc function
:rtype: builtins.function
"""

@functools.wraps(f)
Expand All @@ -55,30 +53,27 @@ def wrapping_udfunc(x: float, value: POINTER(c_double)) -> None:
return UDFUNC(wrapping_udfunc)


def SpiceUDFUNS(f) -> UDFUNS:
def SpiceUDFUNS(f: Callable[[float], float]) -> UDFUNS:
"""
Decorator for wrapping python functions in spice udfuns callback type
:param f: function that has one argument of type float, and returns a float
:type f: builtins.function
:return: wrapped udfunc function
:rtype: builtins.function
"""

@functools.wraps(f)
def wrapping_udfuns(x, value):
def wrapping_udfuns(x: float, value: POINTER(c_double)):
result = f(x)
value[0] = c_double(result)

return UDFUNS(wrapping_udfuns)


def SpiceUDFUNB(f):
def SpiceUDFUNB(f) -> UDFUNB:
"""
Decorator for wrapping python functions in spice udfunb callback type
:param f: function to be wrapped
:type f: builtins.function
:return: wrapped udfunb function
:rtype: builtins.function
"""

@functools.wraps(f)
Expand All @@ -89,13 +84,12 @@ def wrapping_udfunb(udf, et, xbool):
return UDFUNB(wrapping_udfunb)


def SpiceUDSTEP(f):
def SpiceUDSTEP(f) -> UDSTEP:
"""
Decorator for wrapping python functions in spice udstep callback type
:param f: function to be wrapped
:type f: builtins.function
:return: wrapped udstep function
:rtype: builtins.function
"""

@functools.wraps(f)
Expand All @@ -106,13 +100,12 @@ def wrapping_udstep(x, value):
return UDSTEP(wrapping_udstep)


def SpiceUDREFN(f):
def SpiceUDREFN(f) -> UDREFN:
"""
Decorator for wrapping python functions in spice udrefn callback type
:param f: function to be wrapped
:type f: builtins.function
:return: wrapped udrefn function
:rtype: builtins.function
"""

@functools.wraps(f)
Expand All @@ -123,13 +116,12 @@ def wrapping_udrefn(t1, t2, s1, s2, t):
return UDREFN(wrapping_udrefn)


def SpiceUDREPI(f):
def SpiceUDREPI(f) -> UDREPI:
"""
Decorator for wrapping python functions in spice udfrepi callback type
:param f: function to be wrapped
:type f: builtins.function
:return: wrapped udrepi function
:rtype: builtins.function
"""

@functools.wraps(f)
Expand All @@ -139,13 +131,12 @@ def wrapping_udrepi(cnfine, srcpre, srcsurf):
return UDREPI(wrapping_udrepi)


def SpiceUDREPU(f):
def SpiceUDREPU(f) -> UDREPU:
"""
Decorator for wrapping python functions in spice udrepu callback type
:param f: function to be wrapped
:type f: builtins.function
:return: wrapped udrepu function
:rtype: builtins.function
"""

@functools.wraps(f)
Expand All @@ -155,13 +146,12 @@ def wrapping_udrepu(beg, end, et):
return UDREPU(wrapping_udrepu)


def SpiceUDREPF(f):
def SpiceUDREPF(f) -> UDREPF:
"""
Decorator for wrapping python functions in spice udrepf callback type
:param f: function to be wrapped
:type f: builtins.function
:return: wrapped udrepf function
:rtype: builtins.function
"""

@functools.wraps(f)
Expand All @@ -171,13 +161,12 @@ def wrapping_udrepf():
return UDREPF(wrapping_udrepf)


def SpiceUDBAIL(f):
def SpiceUDBAIL(f: Callable[[], bool]) -> UDBAIL:
"""
Decorator for wrapping python functions in spice udbail callback type
:param f: function to be wrapped
:type f: builtins.function
:return: wrapped udbail function
:rtype: builtins.function
"""

@functools.wraps(f)
Expand All @@ -188,16 +177,13 @@ def wrapping_udbail():
return UDBAIL(wrapping_udbail)


def CallUDFUNS(f, x):
def CallUDFUNS(f: UDFUNS, x: float) -> float:
"""
We are given a UDF CFUNCTYPE and want to call it in python
:param f: SpiceUDFUNS
:type f: CFUNCTYPE
:param x: some scalar
:type x: float
:return: value
:rtype: float
"""
value = c_double()
f(x, byref(value))
Expand Down

0 comments on commit 9a145bc

Please sign in to comment.