Repository: OpenBB-finance/OpenBBTerminal
File: openbb_platform/providers/yfinance/openbb_yfinance/models/equity_screener.py (Python)

Code before:
        default=None,
        description="Filter by a beta less than this value.",
    )
    limit: int | None = Field(
        default=200,
        description="Limit the number of results returned. Default is, 200. Set to, 0, for all results.",
    )

    @field_validator("country", mode="before")
    @classmethod
    def _validate_country(cls, v):
        """Validate and normalize country input."""
        if v is None or v == "all":
            return v
        # Convert Country type or string to lowercase alpha-2 for YFinance
        if isinstance(v, Country):
            country_code = v.alpha_2.lower()
        else:
            try:
                country_code = Country(v).alpha_2.lower()
            except ValueError:
                return v  # Let it fail at API level if invalid
        if country_code not in COUNTRIES:
            raise ValueError(
                f"Country '{v}' ({country_code.upper()}) is not supported by YFinance. "
                f"Valid options: {', '.join(sorted(COUNTRIES)[:20])}...",
            )
        return country_code


class YFinanceEquityScreenerData(EquityScreenerData, YFPredefinedScreenerData):
    """YFinance Equity Screener Data."""


class YFinanceEquityScreenerFetcher(
    Fetcher[YFinanceEquityScreenerQueryParams, list[YFinanceEquityScreenerData]],
):
    """YFinance Equity Screener Fetcher."""

    @staticmethod
    def transform_query(params: dict[str, Any]) -> YFinanceEquityScreenerQueryParams:
        """Transform query."""
        sector = params.get("sector")
        industry = params.get("industry")

        if industry and sector:
            sec = get_industry_sector(industry)
            if sec and sec != sector:
                choices = "\n    ".join(sorted(INDUSTRY_MAP[sector]))
                raise OpenBBError(
                    ValueError(

Review comment (suggestion):
For clarity, we can also remove the limit on displaying the valid countries in the error message.

```suggestion
        if country_code not in COUNTRIES:
            raise ValueError(
                f"Country '{v}' ({country_code.upper()}) is not supported by YFinance. "
                f"Valid options: {', '.join(sorted(COUNTRIES))}",
            )
```


Code after:
        default=None,
        description="Filter by a beta less than this value.",
    )
    limit: int | None = Field(
        default=200,
        description="Limit the number of results returned. Default is, 200. Set to, 0, for all results.",
    )

    @field_validator("country", mode="before")
    @classmethod
    def _validate_country(cls, v):
        """Validate and normalize country input."""
        if v is None or v == "all":
            return v
        # Convert Country type or string to lowercase alpha-2 for YFinance
        if isinstance(v, Country):
            country_code = v.alpha_2.lower()
        else:
            try:
                country_code = Country(v).alpha_2.lower()
            except ValueError:
                country_code = v.strip().lower()
        if country_code not in COUNTRIES:
            raise ValueError(
                f"Country '{v}' ({country_code.upper()}) is not supported by YFinance. "
                f"Valid options: {', '.join(sorted(COUNTRIES))}",
            )
        return country_code


class YFinanceEquityScreenerData(EquityScreenerData, YFPredefinedScreenerData):
    """YFinance Equity Screener Data."""


class YFinanceEquityScreenerFetcher(
    Fetcher[YFinanceEquityScreenerQueryParams, list[YFinanceEquityScreenerData]],
):
    """YFinance Equity Screener Fetcher."""

    @staticmethod
    def transform_query(params: dict[str, Any]) -> YFinanceEquityScreenerQueryParams:
        """Transform query."""
        sector = params.get("sector")
        industry = params.get("industry")

        if industry and sector:
            sec = get_industry_sector(industry)
            if sec and sec != sector:
                choices = "\n    ".join(sorted(INDUSTRY_MAP[sector]))
                raise OpenBBError(
                    ValueError(