Yes, I use type hints extensively. It helps with autocompletion and let's you catch bugs before you even run the code. lt is also much easier to use a 3rd party module if functions/methods are annotated, since you know what kinds of arguments they expect from you. Answer from LongerHV on reddit.com
🌐
Python documentation
docs.python.org › 3 › library › typing.html
typing — Support for type hints
1 week ago - Doing Derived = NewType('Derived', Original) will make the static type checker treat Derived as a subclass of Original, which means a value of type Original cannot be used in places where a value of type Derived is expected. This is useful when you want to prevent logic errors with minimal runtime cost. Added in version 3.5.2. Changed in version 3.10: NewType is now a class rather than a function. As a result, there is some additional runtime cost when calling NewType over a regular function. Changed in version 3.11: The performance of calling NewType has been restored to its level in Python 3.9.
🌐
Python
docs.python.org › 3.9 › library › typing.html
typing — Support for type hints — Python 3.9.24 documentation
Use object to indicate that a value could be any type in a typesafe manner. Use Any to indicate that a value is dynamically typed. Initially PEP 484 defined the Python static type system as using nominal subtyping.
Discussions

Are you using types in Python ?
Yes, I use type hints extensively. It helps with autocompletion and let's you catch bugs before you even run the code. lt is also much easier to use a 3rd party module if functions/methods are annotated, since you know what kinds of arguments they expect from you. More on reddit.com
🌐 r/Python
386
383
October 22, 2023
python - When/why use types from typing module for type hints - Stack Overflow
What is exactly the 'right' way for type hinting? My IDE (and resulting code) works fine for type hints using either of below options, but some types can be imported from the typing module. Is ther... More on stackoverflow.com
🌐 stackoverflow.com
Types in Python and the use of typing library
Actually, the typing library is now mostly unnecessary. When types were first introduced, you had to use classes from there for almost everything: although you could use int and float as you have above, if you wanted to type a parameter as a list of strings, for example, you had to do use List[str] from that library. Similarly, until Python 3.10 the only way to express a union - for example, a parameter could be an int or a float - was by using Union[int, float]. But now you can do int | float without using any of the typing classes. And the same for optional parameters - before you had to do Optional[str] but now you can do str | None. So, the main remaining uses for that library are specialised things like protocol classes, type variables, generic types, etc. More on reddit.com
🌐 r/learnpython
9
5
November 1, 2023
Pycharm SQLAlchemy Plugin adds typing support for Mapped columns : Python
This has been a long standing issue on Pycharm and nobody on the company seems interested in it. Looks like somebody went ahead and created a... More on old.reddit.com
🌐 r/Python
🌐
GitConnected
levelup.gitconnected.com › modernize-your-python-with-type-hints-a907a15fd904
Modernize your Python with Type Hints | by Bryson Meiling | Level Up Coding
February 17, 2025 - Type hints, introduced in PEP 484 in 2014, are a game-changer to larger python projects. They allow you to add static type information to your code, bringing the benefits of static typing to your dynamically typed Python programs. Skeptic say, “well actually it doesn’t enforce anything at run time” and they’d be right.
🌐
7-Zip Documentation
documentation.help › python-3-7-3 › typing.html
typing — Support for type hints - Python 3.7.3 Documentation
March 25, 2019 - Type[Any] is equivalent to Type which in turn is equivalent to type, which is the root of Python’s metaclass hierarchy.
🌐
W3Schools
w3schools.com › python › ref_module_typing.asp
Python typing Module
Use it to add type annotations for better code documentation, IDE support, and static type checking with tools like mypy. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Astral
docs.astral.sh › ty › reference › typing-faq
Typing FAQ | ty
3 days ago - This page answers some commonly asked questions about ty and Python's type system.
Find elsewhere
🌐
Python
peps.python.org › pep-0827
PEP 827 – Type Manipulation | peps.python.org
1 week ago - We propose adding powerful type-level introspection and construction facilities to Python’s type system. This design is inspired largely by TypeScript’s conditional and mapped types, but is adapted to the distinct semantics and constraints of Python’s t...
🌐
Real Python
realpython.com › ref › stdlib › typing
typing | Python Standard Library – Real Python
Python’s typing module provides tools for adding type hints to your code.
🌐
Pyrefly
pyrefly.org › python typing 101
Python Typing 101 | Pyrefly
You can also specify a parameter as optional by using Optional type, or now with the | None syntax. # Optional typing example from typing import Optional middle_name: Optional[str] = None # classic nickname: str | None = None # 3.10+ shorthand ... Both variables can either be a string or None. Optional[str] is the traditional syntax (pre-Python 3.10).
🌐
GitHub
github.com › python › typing
GitHub - python/typing: Python static typing home. Hosts the documentation and a user help forum. · GitHub
Python static typing home. Hosts the documentation and a user help forum. - python/typing
Author   python
🌐
FastAPI
fastapi.tiangolo.com › python-types
Python Types Intro - FastAPI
Then you can declare a variable to be of type Person: ... class Person: def __init__(self, name: str): self.name = name def get_person_name(one_person: Person): return one_person.name ... Notice that this means "one_person is an instance of the class Person". It doesn't mean "one_person is the class called Person". Pydantic is a Python library to perform data validation.
🌐
Python
typing.python.org › en › latest › spec › protocol.html
Protocols — typing documentation
Type checkers should be able to select a correct element from a union after a safe isinstance() or issubclass() call. For narrowing from non-union types, type checkers can use their best judgement (this is intentionally unspecified, since a precise specification would require intersection types). ... © Copyright 2021, The Python Typing Team.
🌐
Medium
medium.com › @AlexanderObregon › how-pythons-type-hinting-and-annotations-work-319d952247a6
How Python’s Type Hinting and Annotations Work | Medium
July 14, 2024 - Type hinting was introduced in Python 3.5 as part of PEP 484. It provides a way to indicate the expected data types of function arguments and return values, adding a layer of clarity to the code. Python remains a dynamically typed language, meaning that type checking is not enforced at runtime.
🌐
Justin A. Ellis
jellis18.github.io › post › 2023-01-15-advanced-python-types
Some Advanced Typing Concepts in Python - Justin A. Ellis
January 15, 2023 - To start off, let me admit that yes, Python is a dynamically (gradually?) typed language. However, with modern Python (3.6+, and really with 3.10+) and static tooling (i.e. mypy, pyright/pylance) it is a pretty robust statically typed language. Most third party libraries either are typed or have types stubs distributed separately.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-typing-module
Python typing module - Use type checkers effectively | DigitalOcean
August 4, 2022 - This is a good way for the programmer to hint the type of the object(s) being used, during compilation time itself and ensure that the type checkers work correctly. This makes Python code much more readable and robust as well, to other readers!
🌐
Reddit
reddit.com › r/learnpython › types in python and the use of typing library
r/learnpython on Reddit: Types in Python and the use of typing library
November 1, 2023 -

Greetings fellow humans,

I am using types in Python which now are supported natively as type hints.

Why and when should I use the typing library.

Code example:

def division(a: int, b: int) -> float:
  if b != 0:
    return a/b
  else:
    print("Division by zero is not allowed") 

In the above example I am using typing hints without the typing library.

Top answer
1 of 5
6
Actually, the typing library is now mostly unnecessary. When types were first introduced, you had to use classes from there for almost everything: although you could use int and float as you have above, if you wanted to type a parameter as a list of strings, for example, you had to do use List[str] from that library. Similarly, until Python 3.10 the only way to express a union - for example, a parameter could be an int or a float - was by using Union[int, float]. But now you can do int | float without using any of the typing classes. And the same for optional parameters - before you had to do Optional[str] but now you can do str | None. So, the main remaining uses for that library are specialised things like protocol classes, type variables, generic types, etc.
2 of 5
4
In more recent versions of Python, you need it less and less. Now that we can create type variables in 3.12 without it it only has a handful of uses left, mainly typing.Unpack for type hinting keyword arguments, or typing.NamedTuple which actually works differently from collections.namedtuple. Built-in collection types (list, tuple, collections.deque) have replaced their typing aliases (eg. typing.List), generics can now use the collections.abc counterparts, typing.Union and many similar ones have been replaced by operators, from __future__ import annotations means you don't need to worry about nested declarations, and so on. Basically, for the most part you don't need to touch it unless you want to support older versions, or you have specific needs. For example typing.assert_never is a relatively new addition which enables exhaustive checks of structural pattern matching: from enum import IntEnum, auto from typing import assert_never class WalkingState(IntEnum): STANDING = auto() WALKING = auto() RUNNING = auto() state = WalkingState.RUNNING match state: case WalkingState.STANDING: print("Standing") case WalkingState.WALKING: print("Walking") case _: assert_never(_) # We forgot to handle a case This will make the type checker scream at you until you've handled every option in the enum. Another example is the typing.TYPE_CHECKING constant, which is set to True when a type checker runs. This way you can, for example, only import things needed by the type checker without doing that at runtime. from typing import TYPE_CHECKING if TYPE_CHECKING: from collections.abc import Collection from numbers import Number def foo(nums: Collection[Number]) -> Number: return sum(nums) The last one in particular is something Ruff has drilled into my memory by now.
🌐
Python
typing.python.org › en › latest › spec › annotations.html
Type annotations — typing documentation
The grammar assumes the code has already been parsed as Python code, and loosely follows the structure of the AST. Syntactic details like comments and whitespace are ignored. <Name> refers to a special form. Most special forms must be imported from typing or typing_extensions, except for None, InitVar, type, and tuple.
🌐
Python
peps.python.org › pep-0484
PEP 484 – Type Hints | peps.python.org
The proposal is strongly inspired by mypy. For example, the type “sequence of integers” can be written as Sequence[int]. The square brackets mean that no new syntax needs to be added to the language. The example here uses a custom type Sequence, imported from a pure-Python module typing.