Skip to content

#334 - Add more type annotations - #364

Merged
reckart merged 3 commits into
mainfrom
refactoring/334-Add-more-type-annotations
Jul 31, 2026
Merged

reckart merged 3 commits into
mainfrom
refactoring/334-Add-more-type-annotations

Conversation

@reckart

@reckart reckart commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

What's in the PR

  • Move Sofa attribute type information from Sphinx docstring prefixes into real type annotations
  • Widen optional string parameters to Optional[str] in offset-mapping and sofaString APIs
  • Annotate the CAS sofa registry as dict[str, Sofa] and the XMI sofa attribute dict as Dict[str, Any]
  • Widen Cas sofa property setters and getters to Optional[str] for sofa_string, sofa_mime, sofa_uri; fix sofa_array to return Optional[FeatureStructure] instead of str
  • Add ListBase, NonEmptyListBase, and NonEmptyFSListBase static type classes to model UIMA list node hierarchies with proper head/tail features
  • Add TYPE_NAME_LIST_BASE constant and _NON_EMPTY_PRIMITIVE_LIST_TYPES type set
  • Add TypeGuard functions is_list_fs, is_non_empty_list_fs, is_non_empty_fs_list for static narrowing of list node types
  • Wire ListBase and NonEmptyFSListBase dispatch in Type.get_class via _is_subtype_of checks on _NON_EMPTY_PRIMITIVE_LIST_TYPES
  • Improve XMI serialization sink parameter from IO to IO[bytes] for type clarity
  • Refactor _collect_list_elements to accept Optional[FeatureStructure], return List[Any], and use is_non_empty_list_fs TypeGuard instead of hasattr for list walk termination
  • Add Optional import to xmi.py typing imports
  • Add return type annotations to all 31 pytest fixtures with -> str, and 2 fixtures returning List[FeatureStructure]
  • Add parameter type annotations to pytest fixture parameters in test functions (small_xmi_path, small_typesystem_xml, etc. as str)
  • Add parameter type annotations to @pytest.mark.parametrize arguments across test_xmi.py, test_json.py, test_typesystem.py (typesystem_xml, xmi, json_path as str; ann_begin, ann_end as int; overlap, expect_kept as bool; expect_begin, expect_end as Optional[int]; name, rangeTypeName as str; elementType, multipleReferencesAllowed as Optional[str] / Optional[bool])
  • Type helper functions _make_fs_list and _fs_list_elements in test_cas.py with signatures using TypeSystem, Optional[FeatureStructure], and List[Optional[FeatureStructure]]
  • Refactor _fs_list_elements to use is_non_empty_list_fs() TypeGuard instead of hasattr for list node termination detection
  • Add typing imports (List, Optional) and cassis.typesystem imports (FeatureStructure, TypeSystem, is_non_empty_list_fs) to test files

How to test manually

  • No specific test procedure

Automatic testing

  • PR includes unit tests

Documentation

  • PR updates documentation

- Move Sofa attribute type information from Sphinx docstring prefixes into real type annotations
- Widen optional string parameters to Optional[str] in offset-mapping and sofaString APIs
- Annotate the CAS sofa registry as dict[str, Sofa] and the XMI sofa attribute dict as Dict[str, Any]
@reckart reckart added this to the 0.12.0 milestone Jul 31, 2026
@reckart reckart self-assigned this Jul 31, 2026
@reckart reckart added this to Kanban Jul 31, 2026
@github-project-automation github-project-automation Bot moved this to In progress in Kanban Jul 31, 2026
reckart added 2 commits July 31, 2026 23:24
- Widen Cas sofa property setters and getters to Optional[str] for sofa_string, sofa_mime, sofa_uri; fix sofa_array to return Optional[FeatureStructure] instead of str
- Add ListBase, NonEmptyListBase, and NonEmptyFSListBase static type classes to model UIMA list node hierarchies with proper head/tail features
- Add TYPE_NAME_LIST_BASE constant and _NON_EMPTY_PRIMITIVE_LIST_TYPES type set
- Add TypeGuard functions is_list_fs, is_non_empty_list_fs, is_non_empty_fs_list for static narrowing of list node types
- Wire ListBase and NonEmptyFSListBase dispatch in Type.get_class via _is_subtype_of checks on _NON_EMPTY_PRIMITIVE_LIST_TYPES
- Improve XMI serialization sink parameter from IO to IO[bytes] for type clarity
- Refactor _collect_list_elements to accept Optional[FeatureStructure], return List[Any], and use is_non_empty_list_fs TypeGuard instead of hasattr for list walk termination
- Add Optional import to xmi.py typing imports
- Add return type annotations to all 31 pytest fixtures with -> str, and 2 fixtures returning List[FeatureStructure]
- Add parameter type annotations to pytest fixture parameters in test functions (small_xmi_path, small_typesystem_xml, etc. as str)
- Add parameter type annotations to @pytest.mark.parametrize arguments across test_xmi.py, test_json.py, test_typesystem.py (typesystem_xml, xmi, json_path as str; ann_begin, ann_end as int; overlap, expect_kept as bool; expect_begin, expect_end as Optional[int]; name, rangeTypeName as str; elementType, multipleReferencesAllowed as Optional[str] / Optional[bool])
- Type helper functions _make_fs_list and _fs_list_elements in test_cas.py with signatures using TypeSystem, Optional[FeatureStructure], and List[Optional[FeatureStructure]]
- Refactor _fs_list_elements to use is_non_empty_list_fs() TypeGuard instead of hasattr for list node termination detection
- Add typing imports (List, Optional) and cassis.typesystem imports (FeatureStructure, TypeSystem, is_non_empty_list_fs) to test files
@reckart
reckart merged commit d812239 into main Jul 31, 2026
5 checks passed
@reckart
reckart deleted the refactoring/334-Add-more-type-annotations branch July 31, 2026 21:40
@github-project-automation github-project-automation Bot moved this from In progress to Done in Kanban Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant