Class ClassType
java.lang.Object
org.sonar.plugins.python.api.types.v2.ClassType
- All Implemented Interfaces:
PythonType
ClassType
-
Field Summary
Fields inherited from interface org.sonar.plugins.python.api.types.v2.PythonType
UNKNOWN -
Constructor Summary
ConstructorsConstructorDescriptionClassType(String name, String fullyQualifiedName, Set<Member> members, List<PythonType> attributes, List<TypeWrapper> superClasses, List<PythonType> metaClasses, boolean hasDecorators, boolean isGeneric, LocationInFile locationInFile) -
Method Summary
Modifier and TypeMethodDescriptionbooleanareAttributesCompatible(ClassType other) booleanbooleanbooleaninheritedMember(String memberName) instancesHaveMember(String memberName) booleanisASubClassFrom(ClassType other) isCompatibleWith(PythonType another) booleanbooleanReturnstruefor built-in containers whose typeshed declaration includes fictional ABC inheritance that does not exist at runtime (e.g.key()members()mro()Computes the C3 linearization (Method Resolution Order) for this class.name()resolveMember(String memberName) Attempts to resolve a PythonType's member It should return Optional.empty() when the member doesn't exist, and PythonType.UNKNOWN when the member may exist but can't be resolvedtoString()static booleanwouldHaveValidMro(List<ClassType> bases) Returns whether C3 linearization would succeed at runtime for a hypothetical class whose direct bases are exactlybasesin order.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.sonar.plugins.python.api.types.v2.PythonType
typeSource, unwrappedType
-
Constructor Details
-
ClassType
public ClassType(String name, String fullyQualifiedName, Set<Member> members, List<PythonType> attributes, List<TypeWrapper> superClasses, List<PythonType> metaClasses, boolean hasDecorators, boolean isGeneric, @Nullable LocationInFile locationInFile) -
ClassType
-
-
Method Details
-
displayName
- Specified by:
displayNamein interfacePythonType
-
instanceDisplayName
- Specified by:
instanceDisplayNamein interfacePythonType
-
isCompatibleWith
- Specified by:
isCompatibleWithin interfacePythonType
-
isASubClassFrom
-
areAttributesCompatible
-
key
- Specified by:
keyin interfacePythonType
-
resolveMember
Description copied from interface:PythonTypeAttempts to resolve a PythonType's member It should return Optional.empty() when the member doesn't exist, and PythonType.UNKNOWN when the member may exist but can't be resolved- Specified by:
resolveMemberin interfacePythonType
-
inheritedMember
-
hasUnresolvedHierarchy
public boolean hasUnresolvedHierarchy() -
mro
Computes the C3 linearization (Method Resolution Order) for this class.Returns
Optional.empty()if:- the type hierarchy is unresolved (
hasUnresolvedHierarchy()istrue), or - the MRO cannot be computed because the base class ordering creates a conflict
(i.e. what Python raises as a
TypeErrorat class definition time).
The returned list starts with
thisand ends with the most-distant ancestor.- See Also:
- the type hierarchy is unresolved (
-
wouldHaveValidMro
Returns whether C3 linearization would succeed at runtime for a hypothetical class whose direct bases are exactlybasesin order. Uses Python's runtime view of built-in containers: typeshed-only inheritance edges fromdict/list/set/… to theircollections.abc/typingABCs (which at runtime areabc.ABCMeta.register()virtual subclasses, not real bases) are ignored. This way, valid Python code such asclass N(MutableMapping, dict): passis not flagged.Precondition: every element of
basesis non-null and fully resolved (no unresolved hierarchy), matching whatmro()requires for each base.If any base has an empty
mro()because an ancestor's hierarchy is invalid, this returnstrue— the failure is not attributable to the merge of these bases alone. -
isVirtualAbcSubclassingBuiltin
public boolean isVirtualAbcSubclassingBuiltin()Returnstruefor built-in containers whose typeshed declaration includes fictional ABC inheritance that does not exist at runtime (e.g.dict,list,set). SeewouldHaveValidMro(List). -
hasMember
- Specified by:
hasMemberin interfacePythonType
-
hasMetaClass
public boolean hasMetaClass() -
instancesHaveMember
-
definitionLocation
- Specified by:
definitionLocationin interfacePythonType
-
toString
-
name
- Specified by:
namein interfacePythonType
-
fullyQualifiedName
-
members
-
attributes
-
superClasses
-
metaClasses
-
hasDecorators
public boolean hasDecorators() -
isGeneric
public boolean isGeneric()
-