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