From efcc4cfbe121203443d146961f5fce2c9d117a69 Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Thu, 28 Nov 2024 14:42:37 -0500 Subject: [PATCH] add is_str --- crates/ruff_python_semantic/src/analyze/typing.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/ruff_python_semantic/src/analyze/typing.rs b/crates/ruff_python_semantic/src/analyze/typing.rs index 9cf8888b72f7db..6a07feeb147f1f 100644 --- a/crates/ruff_python_semantic/src/analyze/typing.rs +++ b/crates/ruff_python_semantic/src/analyze/typing.rs @@ -665,6 +665,14 @@ impl BuiltinTypeChecker for IntChecker { const EXPR_TYPE: PythonType = PythonType::Number(NumberLike::Integer); } +struct StrChecker; + +impl BuiltinTypeChecker for StrChecker { + const BUILTIN_TYPE_NAME: &'static str = "str"; + const TYPING_NAME: Option<&'static str> = None; + const EXPR_TYPE: PythonType = PythonType::String; +} + pub struct IoBaseChecker; impl TypeChecker for IoBaseChecker { @@ -779,6 +787,11 @@ pub fn is_int(binding: &Binding, semantic: &SemanticModel) -> bool { check_type::(binding, semantic) } +/// Test whether the given binding can be considered a string. +pub fn is_str(binding: &Binding, semantic: &SemanticModel) -> bool { + check_type::(binding, semantic) +} + /// Test whether the given binding can be considered a set. /// /// For this, we check what value might be associated with it through it's initialization and