[flake8-use-pathlib] Fix PTH123 false positive when open is passed a file descriptor from a function call (#17705)

## Summary
Includes minor changes to the semantic type inference to help detect the
return type of function call.

Fixes #17691

## Test Plan

Snapshot tests
This commit is contained in:
Victor Hugo Gomes 2025-04-29 17:51:38 -03:00 committed by GitHub
parent 93d6a3567b
commit 8c68d30c3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 5 deletions

View file

@ -639,6 +639,18 @@ pub fn check_type<T: TypeChecker>(binding: &Binding, semantic: &SemanticModel) -
_ => false,
},
BindingKind::FunctionDefinition(_) => match binding.statement(semantic) {
// ```python
// def foo() -> int:
// ...
// ```
Some(Stmt::FunctionDef(ast::StmtFunctionDef { returns, .. })) => returns
.as_ref()
.is_some_and(|return_ann| T::match_annotation(return_ann, semantic)),
_ => false,
},
_ => false,
}
}