Table of Contents

Class DiscriminatedUnion

Tags assigned by a union to each of its members, carried in the specified property.

Annotate the root of a SchemaUnion, or the value of a union alias, with an instance. The tag of each member is its class name, or its fully qualified type name when qualified is set, so the members do not declare the tag themselves. With qualified tags, the module of each member must declare its namespace before the union is defined. A member instance is resolved by its exact class, so an instance of another class with the same name is rejected.

The tag property follows the alias generator of the union members.

Constructors

View Source

DiscriminatedUnion

Declares the property carrying the tag, and whether tags are qualified.

Declaration
DiscriminatedUnion(property_name: str, *, qualified: bool = False)
Parameters
Type Name Description
str property_name

The name of the property carrying the tag of each union member.

bool qualified

True to tag each union member with its fully qualified type name; otherwise with its class name.