ist die Liste der Typen I häufig verwenden:
string: str
unicode: unicode
integer: int
float: float
general dictionary: dict
general list: list
general tuple: tuple
None: None
not defined: Any
your own object: MySpecialClass
specific tuple: (str, int)
specific list: list of str
specific dict: dict[str, int]
multiple options: str or list
Beispiel:
import requests
def example_function(list_var, str_var, num_var, request_var):
"""
:param list_var:
:type list_var: list of str
:param str_var:
:type str_var: str or unicode
:param num_var:
:type num_var: int
:param request_var:
:type request_var: requests.models.Request
:return:
:rtype: (list of dict) or None
"""
return [{}]
example_function(
['a', 'b'],
u'unicode accepted because stated',
1.234,
requests.Request('GET', 'http://going/somewhere')
)
richtige Format für Antrag folgende Modul und Klasse von __init__.py
Dann wurde gefunden, wenn man drückt Strg und schwebt über den Funktionsaufruf, man bekommt einen Typ-Hilfetext. Dies ist sehr nützlich, da die Namenskonventionen PEP 8 typenspezifisch vage sind.
In diesem Fall wird der Hilfetext sein:
Inferred type: (list_var: List[str], str_var: Union[str, unicode], num_var: int, request_var: Request) -> Optional[List[dict]]
Und eine Warnung für das num_var
Argument:
Expected type 'int', got 'float'