Class ClassType

java.lang.Object
org.sonar.plugins.python.api.types.v2.ClassType
All Implemented Interfaces:
PythonType

@Beta public final class ClassType extends Object implements PythonType
ClassType
  • Constructor Details

  • Method Details

    • displayName

      public Optional<String> displayName()
      Specified by:
      displayName in interface PythonType
    • instanceDisplayName

      public Optional<String> instanceDisplayName()
      Specified by:
      instanceDisplayName in interface PythonType
    • isCompatibleWith

      public TriBool isCompatibleWith(PythonType another)
      Specified by:
      isCompatibleWith in interface PythonType
    • isASubClassFrom

      @Beta public boolean isASubClassFrom(ClassType other)
    • areAttributesCompatible

      @Beta public boolean areAttributesCompatible(ClassType other)
    • key

      public String key()
      Specified by:
      key in interface PythonType
    • resolveMember

      public Optional<PythonType> resolveMember(String memberName)
      Description copied from interface: PythonType
      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 resolved
      Specified by:
      resolveMember in interface PythonType
    • inheritedMember

      public Optional<PythonType> inheritedMember(String memberName)
    • hasUnresolvedHierarchy

      public boolean hasUnresolvedHierarchy()
    • mro

      public Optional<List<ClassType>> mro()
      Computes the C3 linearization (Method Resolution Order) for this class.

      Returns Optional.empty() if:

      • the type hierarchy is unresolved (hasUnresolvedHierarchy() is true), or
      • the MRO cannot be computed because the base class ordering creates a conflict (i.e. what Python raises as a TypeError at class definition time).

      The returned list starts with this and ends with the most-distant ancestor.

      See Also:
    • wouldHaveValidMro

      public static boolean wouldHaveValidMro(List<ClassType> bases)
      Returns whether C3 linearization would succeed at runtime for a hypothetical class whose direct bases are exactly bases in order. Uses Python's runtime view of built-in containers: typeshed-only inheritance edges from dict/list/set/… to their collections.abc / typing ABCs (which at runtime are abc.ABCMeta.register() virtual subclasses, not real bases) are ignored. This way, valid Python code such as class N(MutableMapping, dict): pass is not flagged.

      Precondition: every element of bases is non-null and fully resolved (no unresolved hierarchy), matching what mro() requires for each base.

      If any base has an empty mro() because an ancestor's hierarchy is invalid, this returns true — the failure is not attributable to the merge of these bases alone.

    • isVirtualAbcSubclassingBuiltin

      public boolean isVirtualAbcSubclassingBuiltin()
      Returns true for built-in containers whose typeshed declaration includes fictional ABC inheritance that does not exist at runtime (e.g. dict, list, set). See wouldHaveValidMro(List).
    • hasMember

      public TriBool hasMember(String memberName)
      Specified by:
      hasMember in interface PythonType
    • hasMetaClass

      public boolean hasMetaClass()
    • instancesHaveMember

      public TriBool instancesHaveMember(String memberName)
    • definitionLocation

      public Optional<LocationInFile> definitionLocation()
      Specified by:
      definitionLocation in interface PythonType
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • name

      public String name()
      Specified by:
      name in interface PythonType
    • fullyQualifiedName

      public String fullyQualifiedName()
    • members

      public Set<Member> members()
    • attributes

      public List<PythonType> attributes()
    • superClasses

      public List<TypeWrapper> superClasses()
    • metaClasses

      public List<PythonType> metaClasses()
    • hasDecorators

      public boolean hasDecorators()
    • isGeneric

      public boolean isGeneric()