Fix Python – Type hinting a collection of a specified type

Using Python 3’s function annotations, it is possible to specify the type of items contained within a homogeneous list (or other collection) for the purpose of type hinting in PyCharm and other IDEs?
A pseudo-python code example for a list of int:
def my_func(l:list):
pass

I know it’s possible using Docstring…
def my_func(l):
“””
….

Fix Python – Python type hinting without cyclic imports

I’m trying to split my huge class into two; well, basically into the “main” class and a mixin with additional functions, like so:
main.py file:
import mymixin.py

class Main(object, MyMixin):
def func1(self, xxx):

mymixin.py file:
class MyMixin(object):
def func2(self: Main, xxx): # <--- note the type hint ... Now, w....

Fix Python – How should I use the Optional type hint?

I’m trying to understand how to use the Optional type hint. From PEP-484, I know I can use Optional for def test(a: int = None) either as def test(a: Union[int, None]) or def test(a: Optional[int]).
But how about following examples?
def test(a : dict = None):
#print(a) ==> {‘a’: 1234}
#or
#print(a) ==> None

def test(a : list = None):….

Fix Python – How to annotate types of multiple return values?

How do I use type hints to annotate a function that returns an Iterable that always yields two values: a bool and a str? The hint Tuple[bool, str] is close, except that it limits the return value type to a tuple, not a generator or other type of iterable.
I’m mostly curious because I would like to annotate a function foo() that is used to return ….

Fix Python – Type annotations for *args and **kwargs

I’m trying out Python’s type annotations with abstract base classes to write some interfaces. Is there a way to annotate the possible types of *args and **kwargs?
For example, how would one express that the sensible arguments to a function are either an int or two ints? type(args) gives Tuple so my guess was to annotate the type as Union[Tuple[int….

Fix Python – How do I add default parameters to functions when using type hinting?

If I have a function like this:
def foo(name, opts={}):
pass

And I want to add type hints to the parameters, how do I do it? The way I assumed gives me a syntax error:
def foo(name: str, opts={}: dict) -> str:
pass

The following doesn’t throw a syntax error but it doesn’t seem like the intuitive way to handle this case:
def foo(name: str, op….