Top Description Fields Constructors Methods
org.python.indexer.types

public Class NUnionType

extends NType
Class Inheritance
Imports
org.python.indexer.Indexer, .NBinding, java.util.HashSet, .Set

A union type is a set of several other types. During a union operation, destructuring happens and unknown types are unified.

Field Summary

Modifier and TypeField and Description
private static final int
MAX_RECURSION_DEPTH

Union types can lead to infinite recursion in the occurs check.

private Set<NType>
Inherited from org.python.indexer.types.NType:
LIBRARY_URLREFERENCE_URLTUTORIAL_URL

Constructor Summary

AccessConstructor and Description
public
public
NUnionType(NType... initialTypes)

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
public NType

Returns:

the first non-unknown alternate, or null if none found
firstKnownAlternate
()

Returns the first alternate whose type is not unknown.

public NType

Returns:

the first non-unknown, non-None alternate, or null if none found
firstKnownNonNullAlternate
()

Returns the first alternate whose type is not unknown and is not Indexer#idx.builtins.None.

public Set<NType>
public static NUnionType
newUnion(NType... types)

private static boolean
occurs(NType u, NType v, int depth)

public void
printKids(NType.CyclicTypeRecorder ctr, StringBuilder sb)

Implements abstract org.python.indexer.types.NType.printKids.

Internal method to support printing in the presence of type-graph cycles.

public void
setTypes(Set<NType> types)

public static NType
Inherited from org.python.indexer.types.NType:
asClassTypeasDictTypeasFuncTypeasInstanceTypeasListTypeasModuleTypeasTupleTypeasUnionTypeasUnknownTypefollowgetTableisClassTypeisDictTypeisFuncTypeisInstanceTypeisListTypeisModuleTypeisNativeisNumTypeisStrTypeisTupleTypeisUnionTypeisUnknownTypeprintsetTabletoString

Field Detail

MAX_RECURSION_DEPTHback to summary
private static final int MAX_RECURSION_DEPTH

Union types can lead to infinite recursion in the occurs check. Until we've got a handle on these cases, I'm limiting the recursion depth.

See Also
The Occurs Check for an interesting and highly relevant discussion.
typesback to summary
private Set<NType> types

Constructor Detail

NUnionTypeback to summary
public NUnionType()
NUnionTypeback to summary
public NUnionType(NType... initialTypes)

Method Detail

addTypeback to summary
public void addType(NType t)
containsback to summary
public boolean contains(NType t)
firstKnownAlternateback to summary
public NType firstKnownAlternate()

Returns the first alternate whose type is not unknown.

Returns:NType

the first non-unknown alternate, or null if none found

firstKnownNonNullAlternateback to summary
public NType firstKnownNonNullAlternate()

Returns the first alternate whose type is not unknown and is not Indexer#idx.builtins.None.

Returns:NType

the first non-unknown, non-None alternate, or null if none found

getTypesback to summary
public Set<NType> getTypes()
newUnionback to summary
public static NUnionType newUnion(NType... types)
occursback to summary
private static boolean occurs(NType u, NType v, int depth)
See Also
Occurs check
printKidsback to summary
public void printKids(NType.CyclicTypeRecorder ctr, StringBuilder sb)

Implements abstract org.python.indexer.types.NType.printKids.

Doc from org.python.indexer.types.NType.printKids.

Internal method to support printing in the presence of type-graph cycles.

Annotations
@Override
setTypesback to summary
public void setTypes(Set<NType> types)
unionback to summary
public static NType union(NType u, NType v)