Skip to content

refactor(constants): derive multi-choice lists from Literal aliases#686

Merged
JWCook merged 2 commits into
pyinat:mainfrom
LarytheLord:feat/reuse-constant-literal-values-685
Feb 28, 2026
Merged

refactor(constants): derive multi-choice lists from Literal aliases#686
JWCook merged 2 commits into
pyinat:mainfrom
LarytheLord:feat/reuse-constant-literal-values-685

Conversation

@LarytheLord
Copy link
Copy Markdown
Contributor

Summary

Use typing.get_args() to derive runtime multi-choice constants from existing Literal aliases, so each choice set is declared once and reused for both typing and validation.

Closes #685

Changes

  • added _literal_values() helper in pyinaturalist/constants.py
  • moved multi-choice Literal aliases above runtime constants
  • derived these constants from corresponding literal aliases: INBOXES, COMMUNITY_ID_STATUSES, CONSERVATION_STATUSES, GEOPRIVACY_LEVELS, HISTOGRAM_DATE_FIELDS, HISTOGRAM_INTERVALS, ID_CATEGORIES, ORDER_DIRECTIONS, PROJECT_TYPES, QUALITY_GRADES, SEARCH_PROPERTIES, SOURCES, and CC_LICENSES
  • updated MULTIPLE_CHOICE_PARAMS['iconic_taxa'] to use a shared ICONIC_TAXON_CHOICES list
  • removed the old TODO about Literal[*list] in this area
  • added a regression test to ensure runtime choice lists stay in sync with their literal aliases

Validation

  • uv tool run ruff check pyinaturalist/constants.py test/docs/test_signatures.py
  • uv run pytest -q test/docs/test_signatures.py

@LarytheLord
Copy link
Copy Markdown
Contributor Author

Pushed a small formatting-only follow-up in b6111c3 to fix the CI analyze job (ruff-format adjusted one blank line in constants.py).\n\nLocal validation after that commit:\n- uv tool run ruff check pyinaturalist/constants.py test/docs/test_signatures.py\n- uv run pytest -q test/docs/test_signatures.py (16 passed)

@JWCook JWCook merged commit 5f80227 into pyinat:main Feb 28, 2026
10 checks passed
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.

Reuse constant + literal values for multiple-choice params

2 participants