Skip to content

Commit

Permalink
#310 - Add short_name property to type
Browse files Browse the repository at this point in the history
- Added the property and a test
  • Loading branch information
reckart committed May 4, 2024
1 parent 22232b6 commit f4f56ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions cassis/typesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_typesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit f4f56ec

Please sign in to comment.