Skip to content

Support for from __future__ import annotations#41

Open
mosquito wants to merge 1 commit into
masterfrom
hotfix/from-future-import-annotations-support
Open

Support for from __future__ import annotations#41
mosquito wants to merge 1 commit into
masterfrom
hotfix/from-future-import-annotations-support

Conversation

@mosquito
Copy link
Copy Markdown
Owner

This pull request improves support for Python's from __future__ import annotations (PEP 563/649) in the argclass library by introducing a new utility function to robustly resolve type annotations, even when they are stringified. The changes ensure that type hints are correctly interpreted in modern Python versions and add comprehensive tests to verify this behavior.

Enhanced annotation resolution:

  • Added a new resolve_annotations function in argclass/utils.py that uses typing.get_type_hints() to resolve stringified annotations, falling back to the legacy merge_annotations if needed. This function is now used in both argclass/parser.py and argclass/store.py to retrieve class annotations, replacing direct usage of merge_annotations. [1] [2] [3] [4] [5] [6]

Testing for future annotations:

  • Added a new test file tests/test_future_annotations.py with comprehensive test cases to ensure argclass works correctly when from __future__ import annotations is enabled, covering basic types, optionals, literals, lists, enums, groups, subparsers, and secrets.

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