On this page
  1. typing.ClassVar
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

typing.ClassVar

Prev: typing.ChainMap | Up: typing | Next: typing.clear_overloads
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.ClassVar
Tags: #public #python3 #stdlib #typing


Import

import typing
from typing import ClassVar

Signature & Overview

typing.ClassVar(*args, **kwds)

Special type construct to mark class variables.

Usage

from dataclasses import dataclass
from typing import ClassVar

@dataclass
class User:
    name: str
    species: ClassVar[str] = "human"

u = User("Ada")
assert u.species == "human" and "species" not in u.__dict__

Gotchas

REPL Inspect

from typing import ClassVar
help(ClassVar)

Linked from

Related notes