Extrahieren Sie den Typ eines Callables in MypyPython

Python-Programme
Anonymous
 Extrahieren Sie den Typ eines Callables in Mypy

Post by Anonymous »

Angenommen, ich habe diese Funktionen:

Code: Select all

def mogrify(a: int) -> bool:
return bool(a)

def stream(b: int, f: Callable[[int], bool]) -> bool:
return f(b)
Ich habe einen kanonischen Rückruf, also möchte ich stattdessen gerne
etwas tun wie:

Code: Select all

MyCallback = reveal_type(mogrify)

def stream(b: int, f: MyCallback) -> bool:
return f(b)
Außerdem macht reveal_type selbst nicht wirklich das, was ich will, es ist nicht Teil
von PEP 484, also kann ich das nicht verwenden.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post