Package horizons :: Package ext :: Module typing :: Class Type
[hide private]
[frames] | no frames]

Type Type

    object --+    
             |    
          type --+
                 |
object --+       |
         |       |
   Generic --+   |
             |   |
    object --+   |
             |   |
    ??.Generic --+
                 |
                Type

A special construct usable to annotate class objects.

For example, suppose we have the following classes:

 class User: ...  # Abstract base for User classes
 class BasicUser(User): ...
 class ProUser(User): ...
 class TeamUser(User): ...

And a function that takes a class argument that's a subclass of User and returns an instance of the corresponding class:

 U = TypeVar('U', bound=User)
 def new_user(user_class: Type[U]) -> U:
     user = user_class()
     # (Here we could write the user object to a database)
     return user

 joe = new_user(BasicUser)

At this point the type checker knows that joe has type BasicUser.

Nested Classes [hide private]
  __extra__
type(object) -> the object's type type(name, bases, dict) -> a new type
    Inherited from Generic
  __metaclass__
Metaclass for generic types.
  __next_in_mro__
The most base type
Instance Methods [hide private]
    Inherited from type
 
__call__(x, ...)
x(...)
 
__delattr__(...)
x.__delattr__('name') <==> del x.name
 
__eq__(x, y)
x==y
 
__ge__(x, y)
x>=y
 
__getattribute__(...)
x.__getattribute__('name') <==> x.name
 
__gt__(x, y)
x>y
 
__hash__(x)
hash(x)
the object's type
__init__(object)
x.__init__(...) initializes x; see help(type(x)) for signature
bool
__instancecheck__()
check if an object is an instance
 
__le__(x, y)
x<=y
 
__lt__(x, y)
x<y
 
__ne__(x, y)
x!=y
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__repr__(x)
repr(x)
 
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
bool
__subclasscheck__()
check if a class is a subclass
list of immediate subclasses
__subclasses__()
list
mro()
return a type's method resolution order
    Inherited from object
 
__format__(...)
default object formatter
 
__reduce__(...)
helper for pickle
 
__reduce_ex__(...)
helper for pickle
int
__sizeof__()
size of object in memory, in bytes
 
__str__(x)
str(x)
 
__subclasshook__(...)
Abstract classes can override this to customize issubclass().
Class Variables [hide private]
  __abstractmethods__ = frozenset([])
  __origin__ = None
hash(x)

Inherited from unreachable.Generic: __parameters__

Inherited from unreachable.Generic (private): _abc_negative_cache_version

    Inherited from Generic
  __args__ = None
hash(x)
  _abc_cache = <_weakrefset.WeakSet object at 0x7f8bace75b50>
  _abc_negative_cache = <_weakrefset.WeakSet object at 0x7f8bace...
  _abc_registry = <_weakrefset.WeakSet object at 0x7f8bace75b10>
Properties [hide private]
    Inherited from type
  __base__
  __bases__
  __basicsize__
  __dictoffset__
  __flags__
  __itemsize__
  __mro__
  __name__
  __weakrefoffset__
    Inherited from object
  __class__
the object's class