Top "Type-hinting" questions

Type hinting binds function arguments to specific objects or strongly types them.

Is it possible to type hint more than one type?

Can I allow two different types using type hinting? E.g. parameter $requester could be either of User or File: …

php type-hinting php-8
How do I annotate types in a for-loop

I want to annotate a type of a variable in a for-loop. I tried this: for i: int in range(5): …

python for-loop pycharm type-hinting python-3.6
Subclass in type hinting

I want to allow type hinting using Python 3 to accept sub classes of a certain class. E.g.: class A: …

python subclass type-hinting
Iterable objects and array type hinting?

I have a lot of functions that either have type hinting for arrays or use is_array() to check the …

php iterator type-hinting
Type annotations for Enum value

I have this piece of code: import enum class Color(enum.Enum): RED = '1' BLUE = '2' GREEN = '3…

python python-3.x type-hinting typing type-annotation
How to use Python type hints with Django QuerySet?

Is it possible to specify type of records in Django QuerySet with Python type hints? Something like QuerySet[SomeModel]? For …

python django type-hinting
php7 void return type not working?

I have a problem with return types in php7, specially "void". it works with all other types, int, string, null, …

php return-type type-hinting php-7
Specifying a type to be a List of numbers (ints and/or floats)?

How do I specific a function can take a list of numbers which can be ints or floats? I tried …

python types type-hinting mypy
Type hinting in class variables

<?php namespace Sandbox; class Sandbox { private Connectors\ISandboxConnector $connection; public function __construct(Connectors\ISandboxConnector $conn) { $this->connection = $conn; } } ?&…

php oop type-hinting
Why I am suddenly getting a "Typed property must not be accessed before initialization" error when introducing properties type hints?

I have updated my class definitions to make use of the newly introduced property type hints, like this: class Foo { …

php doctrine-orm php-7 type-hinting php-7.4