Files
OpenBB/openbb_platform/core/tests
John Seong f0c3742729 feat(platform): standardize country inputs with ISO 3166 Country type (#7333)
* feat(platform): standardize country inputs using pydantic-extra-types

Add CountryParam type that accepts:
- ISO 3166-1 alpha-2 codes (e.g., 'US', 'us')
- Full country names (e.g., 'United States')
- lower_snake_case names (e.g., 'united_states')

Uses pydantic-extra-types for programmatic ISO validation instead of
hardcoded mappings. Serializes to lowercase alpha-2 code by default.

Example usage in FMP equity screener:
- country: CountryParam | None

Partially addresses #6969

* refactor: use Country class inheriting from str for type checker compatibility

- Replace Annotated CountryParam with Country(str) class per maintainer feedback
- Store full pycountry object for access to alpha_2, alpha_3, name, numeric
- Use pycountry directly instead of pydantic-extra-types
- Add support for alpha-3 codes (e.g., 'USA')
- Update tests to cover new functionality

* Replace pycountry with static JSON country data

- Add country_data.json with ISO 3166-1 data (20KB vs 6MB pycountry)
- Update Country class to use static JSON lookup
- Remove pycountry dependency from pyproject.toml
- No decompression needed, data loaded once at import

* fix(lint): D402 docstring should start with verb

* fix(lint): work around pydocstyle D402 false positive

When a method is named `name` and `.pydocstyle.ini` uses `match = .*\.py`,
pydocstyle incorrectly triggers D402 for any docstring containing the word
"name" anywhere - not just at the start as the rule intends.

Changed docstring from "Return the full country name..." to
"The country's official designation..." to avoid the false positive.

See: https://github.com/PyCQA/pydocstyle/issues/375

* fix(lint): resolve pylint warnings in country_utils

* fix(lint): use ternary for ruff SIM108 in country_utils

* fix(lint): format ternary for black line length

---------

Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
2026-02-09 21:11:11 +00:00
..