Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pydantic Validators show up as unused functions. #3

Open
travischambers opened this issue Feb 24, 2024 · 1 comment
Open

Pydantic Validators show up as unused functions. #3

travischambers opened this issue Feb 24, 2024 · 1 comment

Comments

@travischambers
Copy link

travischambers commented Feb 24, 2024

It seems that all pydantic validators show up as false positives.

Given a module like this query.py

from pydantic import BaseModel, field_validator

class Query(BaseModel):

    limit: int | None = None  # number of rows to output

    @field_validator("limit", mode="before")
    @classmethod
    def limit_must_be_int_or_none(cls, item: int | None) -> int | None:
        """Validate limit."""
        match item:
            case None | int():
                return item
            case _:
                return None

Uncalled will flag the limit_must_be_int_or_none. I assume this is because my code doesn't call it. However, pydantic does call it whenever my Query gets instantiated. It is very much not dead code.

$ uncalled --how both query.py
query.py: Unused function limit_must_be_int_or_none
@elazarg
Copy link
Owner

elazarg commented Feb 25, 2024

Thanks for reporting! This is an instance of the general issue with frameworks, with the twist that it's a decorator. It might be nontrivial to fix in the regex mode. The AST mode will need a dedicated filter.

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

No branches or pull requests

2 participants