Skip to content

Fix docs: non-string annotations are converted, not rejected#85

Open
Builder106 wants to merge 1 commit into
OpenSourceEconomics:mainfrom
Builder106:docs-fix-nonstring-annotation
Open

Fix docs: non-string annotations are converted, not rejected#85
Builder106 wants to merge 1 commit into
OpenSourceEconomics:mainfrom
Builder106:docs-fix-nonstring-annotation

Conversation

@Builder106
Copy link
Copy Markdown

Problem

Several docstrings and docs claim that set_annotations=True requires string annotations and raises NonStringAnnotationError when they are not strings. For example, concatenate_functions:

All annotations must be strings; otherwise, a NonStringAnnotationError is raised.

This has been inaccurate since #67 ("do not require string annotations from users"). The current behavior is to convert non-string annotations to their string representation (via ensure_annotations_are_strings_get_str_repr). In fact, NonStringAnnotationError is never raised anywhere in the source, is not exported from the package, and has no tests:

# functions WITHOUT `from __future__ import annotations`, so annotations are
# real type objects, not strings
def a() -> int: return 1
def b(a: int) -> float: return a + 1.5

f = concatenate_functions({"a": a, "b": b}, targets="b", set_annotations=True)
# No error. inspect.signature(f).return_annotation == "float"  (the string)

Changes

  • Updated the stale docstrings in dag.py (FunctionExecutionInfo, concatenate_functions, _create_combined_function_from_dag, _create_concatenated_function, create_execution_info) to describe the actual convert behavior and removed the false NonStringAnnotationError Raises: entries.
  • Updated the exception table in docs/api.md and the set_annotations note in docs/usage_patterns.ipynb.
  • Added a regression test in tests/test_without_string_annotations.py asserting that concatenate_functions(..., set_annotations=True) converts non-string annotations rather than raising.

Verification

  • pytest: 195 passed
  • ruff check / ruff format --check: clean
  • ty check: clean

One question for maintainers

NonStringAnnotationError is now effectively orphaned — defined in dags/exceptions.py but never raised, not exported, and untested. I left the class in place so this PR stays documentation-only and doesn't change the (informal) exception surface. Happy to either remove it in this PR or open a follow-up if you'd prefer to deprecate/drop it.

The docstrings in dag.py, the exception table in docs/api.md, and the
usage_patterns notebook all stated that `set_annotations=True` requires
string annotations and raises `NonStringAnnotationError` otherwise. This
has been inaccurate since OpenSourceEconomics#67 ("do not require string annotations from
users"): non-string annotations are converted to their string
representation via `ensure_annotations_are_strings`, and
`NonStringAnnotationError` is never raised anywhere in the code base
(nor is it exported or covered by tests).

- Update the stale docstrings (FunctionExecutionInfo, concatenate_functions,
  _create_combined_function_from_dag, _create_concatenated_function,
  create_execution_info) to describe the actual convert behavior and drop
  the false `NonStringAnnotationError` Raises entries.
- Update the docs/api.md exception table and the usage_patterns notebook.
- Add a regression test asserting that concatenate_functions(set_annotations=
  True) converts non-string annotations instead of raising.
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant