Category "type-hinting"

Python 3 type hinting for decorator

Consider the following code: from typing import Callable, Any TFunc = Callable[..., Any] def get_authenticated_user(): return "John" def require_auth() ->

Is it possible to test a function that uses get_type_hints with a doctest?

I have a function that uses typing.get_type_hints. I want to add a documentation test to it. However, it looks like get_type_hints fails to resolve types that a

Python type hint for (any) class

I want to type hint the following function: def get_obj_class(self) -> CLASS_TYPE: return self.o.__class__ CLASS_TYPE should denote classes. self.o could

PyCharm raising Unresolved reference + expression expected for mypy ignore based on error code

I am trying to silence mypy errors based on error codes. This is done using something like this: from foolib import foo # type: ignore[attr-defined] I beli

how to solve the recursion problem when specifying type hints for classes from different files

how to solve the recursion problem when specifying type hints for classes from different files models1.py from models2 import Second @dataclass class First:

Python type hinting with exceptions

I have a function that looks like this: def check_for_errors(result): if 'success' in result: return True if 'error' in result: raise

Python type hint given as a string?

I have a function of this form: def foo(o: "hello") -> dict: # pass I understand that the "-> dict" means that foo returns a dictionary. What I don

How do I type hint a method with the type of the enclosing class?

I have the following code in Python 3: class Position: def __init__(self, x: int, y: int): self.x = x self.y = y def __add__(self, oth

How to docstring kwargs and their expected types

What is the conventional way to express in a docstring the expected types of keyword arguments? Or is this out of principle something I should not be doing at

Cannot pass null argument when using type hinting

The following code: class Type { } function foo(Type $t) { } foo(null); failed at run time: PHP Fatal error: Argument 1 passed to foo() must not be null

What is the return type hint of a generator function?

I'm trying to write a :rtype: type hint for a generator function. What is the type it returns? For example, say I have this functions which yields strings: d