Skip to content

[feature] TypeGuard/TypeIs functions must have at least 1 positional parameter. If it's a method, it must have at least 2 positional parameters. #596

@yangdanny97

Description

@yangdanny97

Describe the Bug

See the sandbox link for examples of the cases we should cover.

We should add the check to this function:

let mut is_classmethod = false;

The return type is calculated here:

let ret = self

Once we get the return type, we can see if we need to have 1 or 2 params based on what kind of function it is, and emit a BadFunctionDefinition error if it doesn't have the required number.

Once this task is done, add an integration test to pyrefly/lib/tests/narrow.rs, run test.py, and commit any generated changes.

Sandbox Link

https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoBUAUEQMRQB8UAksFAIayICmUaArvSACZTDsoAxjCRgUmAM6ZsAG2YRmKGM170p9cagkwNg1gpgALML1xRBMtRLKUoB49wA0sQ62BIQ2qDglIRY+hkGEA4FJTt6BCkYMBdWCWZBMV4ELnoDZhAbKgAKemBlEChAHAIEmWBAXAIoM2KLCQqASgA6EgsrKABhAC4iKD6obmY6GDQAfQBGHLLgBqgAWioAFRYAcU4eAG1UGABdLr7yADkwfAB5AGle-uuQZhh2EHEAMUCEkmuAATaJCXsTK76g2GYwATDk6rMFlBlghmGsuNwtko9gcoMczpdrjc7g9nq9mCRyItXAlgm5UASgbAxgBmHLAMBgSFLVbrRHbPYAqC3e6PKAvGRvKkjUYAFnpjOcACMuMzoayEUjdj1sby8YLKUNqaMAKwSsDOAD0cphcLZSs5qtx-PxJCIwrGADYciaFZsOfsoEcTlALlyedaBUKtSKAOw5AjOBlM+Ys2Hw93Iz3ejFRxmSKAAa2YcAA7rhuHMxDI4P6cXygwSgA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions