DefinitionsInspector

class dsviper.DefinitionsInspector(definitions)

Bases: object

Retrieves registered types by TypeName, and attachments by identifier.

An index taken at construction over definitions, which hold lists and no maps. A type registered afterwards is NOT in it: query_* answers None and check_* raises for a type that exists. Build a new inspector: even when the DefinitionsConst it reads is live, this index is not. It also knows which short names are ambiguous, which is what representation() answers with: the shortest spelling that still names one type.

Look a type up with TypeName(name_space, name), or take one from concept_type_names(), structure_type_names(), enumeration_type_names() or club_type_names(). An attachment takes its identifier as a str.

attachment_identifiers() → set[str]

Return the set of identifiers for all attachments.

check_attachment(identifier: str) → Attachment

Return the attachment whose identifier is identifier, or raise if none is.

check_club(type_name: TypeName) → TypeClub

Return the club named type_name, or raise if none is.

check_concept(type_name: TypeName) → TypeConcept

Return the concept named type_name, or raise if none is.

check_enumeration(type_name: TypeName) → TypeEnumeration

Return the enum named type_name, or raise if none is.

check_structure(type_name: TypeName) → TypeStructure

Return the struct named type_name, or raise if none is.

club_type_names() → set[TypeName]

Return the set of TypeName for all clubs.

concept_type_names() → set[TypeName]

Return the set of TypeName for all concepts.

enumeration_type_names() → set[TypeName]

Return the set of TypeName for all enums.

is_ambiguous(attachment: Attachment) → bool

Return whether attachment needs its key concept qualified.

True when another attachment of the same namespace carries the same name over a key concept of the same SHORT name - two User concepts of different namespaces, each with a profile. A name built from the short form would then name both, which is what DefinitionsConst.inject asks this before it prefixes the namespace.

name_spaces() → set[NameSpace]

Return the set of NameSpace the inspected types are declared in.

query_attachment(identifier: str) → Attachment | None

Return the attachment whose identifier is identifier, or None if none is.

query_club(type_name: TypeName) → TypeClub | None

Return the club named type_name, or None if none is.

query_concept(type_name: TypeName) → TypeConcept | None

Return the concept named type_name, or None if none is.

query_enumeration(type_name: TypeName) → TypeEnumeration | None

Return the enum named type_name, or None if none is.

query_structure(type_name: TypeName) → TypeStructure | None

Return the struct named type_name, or None if none is.

representation(type_name: TypeName) → str

Return the shortest unambiguous spelling of type_name - the namespace is dropped as far as no other type answers to what is left.

structure_type_names() → set[TypeName]

Return the set of TypeName for all structs.