diff --git a/cassis/typesystem.py b/cassis/typesystem.py index cbc5be3..b3dc2ad 100644 --- a/cassis/typesystem.py +++ b/cassis/typesystem.py @@ -710,6 +710,11 @@ def descendants(self) -> Iterator["Type"]: for child in self._children.values(): yield from child.descendants + @property + def short_name(self) -> str: + """The short name of the type (i.e. the part after the last dot).""" + return self.name.split(".")[-1] + def subsumes(self, other_type: "Type") -> bool: """Determines if the type `other_type` is a child of `self`. @@ -838,10 +843,10 @@ def __init__(self, add_document_annotation_type: bool = True): if add_document_annotation_type: self._add_document_annotation_type() - def __iter__(self): + def __iter__(self) -> Iterator[Type]: return self.get_types() - def contains_type(self, typename: str): + def contains_type(self, typename: str) -> bool: """Checks whether this type system contains a type with name `typename`. Args: diff --git a/tests/test_typesystem.py b/tests/test_typesystem.py index cc3cfcd..36fba9e 100644 --- a/tests/test_typesystem.py +++ b/tests/test_typesystem.py @@ -511,6 +511,14 @@ def test_is_array(): assert cas.typesystem.is_array(type.name) == type.name.endswith("Array") +def test_type_name(): + cas = Cas() + + Annotation = cas.typesystem.get_type(TYPE_NAME_ANNOTATION) + assert Annotation.name == TYPE_NAME_ANNOTATION + assert Annotation.short_name == "Annotation" + + def test_get_types(): cas = Cas()