As explained here, you can use Type:

from typing import Type

class X:
    """some class"""

def foo_my_class(my_class: Type[X], bar: str) -> None:
    """ Operate on my_class """
Answer from roipoussiere on Stack Overflow
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ typing.html
typing โ€” Support for type hints
While type hints can be simple classes like float or str, they can also be more complex. The typing module provides a vocabulary of more advanced type hints. New features are frequently added to the typing module.
Discussions

Type-hinting with user defined classes
You can take advantage of typing.TYPE_CHECKING to only import modules for type hinting purposes or use a str to "forward reference" the object in the type hint per PEP 484 . More on reddit.com
๐ŸŒ r/learnpython
22
2
November 14, 2023
python - type hinting within a class - Stack Overflow
However, third party tools (e.g. mypy), use type hints to do static analysis on your code and can generate errors before runtime. Also, starting with python3.7, you can implicitly convert all of your type-hints to strings within a module by using the from __future__ import annotations (and ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Type hints in class using class attributes
Something like: from typing import Generic, TypeVar class A: """Test member A.""" class B: """Test member B.""" T = TypeVar("T") class Grid(Generic[T]): """Grid using Type T coords.""" def __init__(self, coord: T) -> None: self.coord = coord def some_method(self, arg: T) -> None: """Do stuff.""" self.coord = arg a = A() b = B() ga: Grid[A] = Grid(a) # Explicitly type Grid[a] gb = Grid(b) # Recognized as type Grid[b] by inference gx: Grid[A] = Grid(b) # Type error ga.some_method(b) # Type error If not, I'm not understanding your use-case. More on reddit.com
๐ŸŒ r/learnpython
8
1
December 3, 2023
python - Type hints with user defined classes - Stack Overflow
Couldn't seem to find a definitive answer. I want to do a type hint for a function and the type being some custom class that I have defined, called it CustomClass(). And then let's say in some func... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Dagster
dagster.io โ€บ blog โ€บ python-type-hinting
Using Type Hinting in Python Projects
For example, if a variable can ... This function can handle either a string or an integer ยท The Any class is used to indicate that a variable can be of any type....
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ type-hinting with user defined classes
r/learnpython on Reddit: Type-hinting with user defined classes
November 14, 2023 -

I have two custom classes, one of which requires the other as an input argument.

class Authentication(object):
    def __init__(self) -> None:
        self.auth_data = self._resolve_auth()

class Data(object):
    def __init__(self, authentication) -> None:
        self.baseurl = authentication.baseurl
        self.token = authentication.token

I have the Authentication class defined in a seperate file in my project. So my question is, if I want to apply type-hinting to the Data class i.e.

def __init__(self, authentication: Authentication) -> None:

How do I go about doing this without having to import the Authentication class into my file which contains the Data class? It seems like overkill just to get proper type-hinting.

๐ŸŒ
Adam Johnson
adamj.eu โ€บ tech โ€บ 2021 โ€บ 05 โ€บ 16 โ€บ python-type-hints-return-class-not-instance
Python type hints: specify a class rather than an instance thereof - Adam Johnson
May 16, 2021 - In a type hint, if we specify a type (class), then we mark the variable as containing an instance of that type. To specify that a variable instead contains a type, we need to use type[Cls] (or the old syntax typing.Type).
๐ŸŒ
Real Python
realpython.com โ€บ python-type-self
Python's Self Type: How to Annotate Methods That Return self โ€“ Real Python
July 3, 2026 - You annotate SavingsAccount.from_application() with the TBankAccount type variable, and you annotate the cls parameter with type[TBankAccount]. Most static type checkers should recognize this as valid type hinting for both BankAccount and SavingsAccount. The main drawback is that TypeVar is verbose, and a developer can easily forget to instantiate a TypeVar instance or properly bind the instance to a class.
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ how-pythons-type-hinting-and-annotations-work-319d952247a6
How Pythonโ€™s Type Hinting and Annotations Work | Medium
July 14, 2024 - ... Here, the __annotations__ ... type. Type hints are not limited to functions; they can also be used in class definitions to specify the types of attributes and methods....
Find elsewhere
๐ŸŒ
Python
peps.python.org โ€บ pep-0484
PEP 484 โ€“ Type Hints - Python Enhancement Proposals
The minimum requirement is to handle the builtin decorators @property, @staticmethod and @classmethod. The syntax leverages PEP 3107-style annotations with a number of extensions described in sections below. In its basic form, type hinting is used by filling function annotation slots with classes:
๐ŸŒ
Readthedocs
python-type-checking.readthedocs.io โ€บ en โ€บ latest โ€บ types.html
Type Classes โ€” Guide to Python Type Checking 1.0 documentation
The first thing to understand is that type annotations are actual python classes. You must import them from typing to use them. This is admittedly a bit of a nuisance, but it makes more sense when you consider that the syntax integration in python 3.5 means youโ€™re attaching objects to function definitions just as you do when providing a default value to an argument. In fact, you can use typing.get_type_hints() function to inspect type hint objects on a function at runtime, just as you would inspect argument defaults with inspect.getargspec().
๐ŸŒ
Open Water Foundation
learn.openwaterfoundation.org โ€บ owf-learn-python โ€บ lessons โ€บ type-hints โ€บ type-hints
Type Hints - OWF Learn Python
class SomeClass(object): def __init__(self) -> None: Python functions can accept optional parameters. An Optional type hint can be used to indicate that a function parameter is optionally None, as in the following example that accepts a list of str or None as input:
๐ŸŒ
JetBrains
jetbrains.com โ€บ help โ€บ pycharm โ€บ type-hinting-in-product.html
Type hinting in PyCharm | PyCharm Documentation
August 14, 2026 - Select Add type hint for .... Press Enter to complete the action or edit the type if appropriate. You can also use Python stubs to specify the types of variables, functions, and class fields.
๐ŸŒ
Codefinity
codefinity.com โ€บ blog โ€บ A-Comprehensive-Guide-to-Python-Type-Hints
A Comprehensive Guide to Python Type Hints
Learn about type hints in Python, a powerful feature introduced in Python 3.5 to enhance code clarity and maintainability. Find out how type hints improve code readability, aid in debugging, and enhance the overall development experience. Delve into basic annotations for variables and functions, explore complex types like lists and dictionaries, and understand optional and union types.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ type hints in class using class attributes
r/learnpython on Reddit: Type hints in class using class attributes
December 3, 2023 -

I have a class I'm building as a learning tool. It's designed to be subclassed and so it's got some stuff built in to help with that. I'd like to assign an attribute within the class that could be changed when subclassing (or left as the default value), and want to use that to type hint the methods within the class, so that when subclassed it adjusts the type hints to suit the subclass.

class Coord:
    """A generic coordinate class"""
    pass


class 2DCoord:
    """2D coordinates"""
    pass


class Grid:
    coord_type: type[Coord] = Coord

    def some_method(arg: Self.coord_type) -> None:
        pass


class 2DGrid(Grid):
    coord_type = 2DCoord

I want 2DGrid().some_method(arg) to expect a 2DCoord instance as its argument. Self.coord_type is highlighted as an invalid reference in PyCharm because typing.Self doesn't have a coord_type attribute. Is there a correct way to do this? Or is this meant to work but PyCharm isn't interpreting it correctly?

๐ŸŒ
DataCamp
campus.datacamp.com โ€บ courses โ€บ intermediate-object-oriented-programming-in-python โ€บ custom-class-features-and-type-hints
Type hinting with custom classes | Python
# Define an agent class with a constructor, add type hints class Agent: def __init__(self, ____: ____, ____: ____): self.____: ____ = codename self.____: int = ____
๐ŸŒ
Molssi
education.molssi.org โ€บ type-hints-pydantic-tutorial โ€บ chapters โ€บ TypeHintsInPython.html
Type Hints in Python โ€” Python Type Hints, Dataclasses, and Pydantic
Python allows the ability to annotate variables and outputs through the power of โ€œType Hints.โ€ These augment the arguments and optionally the functional returns provide additional data about what types are expected for a particular argument. ... class Molecule: def __init__(self, name, ...
Top answer
1 of 2
287

The former is correct, if arg accepts an instance of CustomClass:

def FuncA(arg: CustomClass):
    #     ^ instance of CustomClass

In case you want the class CustomClass itself (or a subtype), then you should write:

from typing import Type  # you have to import Type

def FuncA(arg: Type[CustomClass]):
    #     ^ CustomClass (class object) itself

Like it is written in the documentation about Typing:

class typing.Type(Generic[CT_co])

A variable annotated with C may accept a value of type C. In contrast, a variable annotated with Type[C] may accept values that are classes themselves - specifically, it will accept the class object of C.

The documentation includes an example with the int class:

a = 3         # Has type 'int'
b = int       # Has type 'Type[int]'
c = type(a)   # Also has type 'Type[int]'

Update 2024: Type is now deprecated in favour of type

2 of 2
41

Willem Van Onsem's answer is of course correct, but I'd like to offer a small update. In PEP 585, type hinting generics were introduced in standard collections. For example, whereas we previously had to say e.g.

from typing import Dict

foo: Dict[str, str] = { "bar": "baz" }

we can now forgo the parallel type hierarchy in the typing module and simply say

foo: dict[str, str] = { "bar": "baz" }

This feature is available in python 3.9+, and also in 3.7+ if using from __future__ import annotations.

In terms of this specific question, it means that instead of from typing import Type, we can now simply annotate classes using the built-in type:

def FuncA(arg: type[CustomClass]):
๐ŸŒ
Cpske
cpske.github.io โ€บ ISP โ€บ type-hints โ€บ introduction
Type Hints โ€“โ€“ An Introduction | Individual Software Process
Python typing Package - the type hints you can use to designate Python types Python Collection Base Classes in the package collections.abc.