Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions crates/ty_ide/src/semantic_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<'db> SemanticTokenVisitor<'db> {
}

match ty {
Type::ClassLiteral(_) => (SemanticTokenType::Class, modifiers),
Type::ClassSingleton(_) => (SemanticTokenType::Class, modifiers),
Type::NonInferableTypeVar(_) | Type::TypeVar(_) => {
(SemanticTokenType::TypeParameter, modifiers)
}
Expand Down Expand Up @@ -370,7 +370,7 @@ impl<'db> SemanticTokenVisitor<'db> {

// Classify based on the inferred type of the attribute
match ty {
Type::ClassLiteral(_) => (SemanticTokenType::Class, modifiers),
Type::ClassSingleton(_) => (SemanticTokenType::Class, modifiers),
Type::FunctionLiteral(_) => {
// This is a function accessed as an attribute, likely a method
(SemanticTokenType::Method, modifiers)
Expand Down Expand Up @@ -1373,10 +1373,10 @@ from typing import List

class MyClass:
CONSTANT = 42

def method(self):
return \"hello\"

@property
def prop(self):
return self.CONSTANT
Expand Down Expand Up @@ -1442,7 +1442,7 @@ u = List.__name__ # __name__ should be variable<CURSOR>
"
class MyClass:
some_attr = \"value\"

obj = MyClass()
# Test attribute that might not have detailed semantic info
x = obj.some_attr # Should fall back to variable, not property
Expand Down Expand Up @@ -1476,10 +1476,10 @@ class MyClass:
lower_case = 24
MixedCase = 12
A = 1

obj = MyClass()
x = obj.UPPER_CASE # Should have readonly modifier
y = obj.lower_case # Should not have readonly modifier
y = obj.lower_case # Should not have readonly modifier
z = obj.MixedCase # Should not have readonly modifier
w = obj.A # Should not have readonly modifier (length == 1)<CURSOR>
",
Expand Down Expand Up @@ -1604,7 +1604,7 @@ def test_function(param: int, other: MyClass) -> Optional[List[str]]:
x: int = 42
y: MyClass = MyClass()
z: List[str] = [\"hello\"]

# Type annotations should be Class tokens:
# int, MyClass, Optional, List, str
return None<CURSOR>
Expand Down Expand Up @@ -1683,7 +1683,7 @@ class MyProtocol(Protocol):
# Value context - MyProtocol is still a class literal, so should be Class
my_protocol_var = MyProtocol

# Type annotation context - should be Class
# Type annotation context - should be Class
def test_function(param: MyProtocol) -> MyProtocol:
return param
<CURSOR>",
Expand Down Expand Up @@ -1719,7 +1719,7 @@ def test_function(param: MyProtocol) -> MyProtocol:
def func[T](x: T) -> T:
return x

# Generic function with TypeVarTuple
# Generic function with TypeVarTuple
def func_tuple[*Ts](args: tuple[*Ts]) -> tuple[*Ts]:
return args

Expand All @@ -1734,10 +1734,10 @@ class Container[T, U]:
def __init__(self, value1: T, value2: U):
self.value1: T = value1
self.value2: U = value2

def get_first(self) -> T:
return self.value1

def get_second(self) -> U:
return self.value2

Expand Down Expand Up @@ -1892,8 +1892,8 @@ class MyClass:
fn test_implicitly_concatenated_strings() {
let test = cursor_test(
r#"x = "hello" "world"
y = ("multi"
"line"
y = ("multi"
"line"
"string")
z = 'single' "mixed" 'quotes'<CURSOR>"#,
);
Expand All @@ -1919,8 +1919,8 @@ z = 'single' "mixed" 'quotes'<CURSOR>"#,
fn test_bytes_literals() {
let test = cursor_test(
r#"x = b"hello" b"world"
y = (b"multi"
b"line"
y = (b"multi"
b"line"
b"bytes")
z = b'single' b"mixed" b'quotes'<CURSOR>"#,
);
Expand Down Expand Up @@ -2040,21 +2040,21 @@ y = "another_global"
def outer():
x = "outer_value"
z = "outer_local"

def inner():
nonlocal x, z # These should be variable tokens
global y # This should be a variable token
x = "modified"
y = "modified_global"
z = "modified_local"

def deeper():
nonlocal x # Variable token
global y, x # Both should be variable tokens
return x + y

return deeper

return inner<CURSOR>
"#,
);
Expand Down Expand Up @@ -2100,11 +2100,11 @@ def outer():
def test():
global x
nonlocal y

# Multiple variables in one statement
global a, b, c
nonlocal d, e, f

return x + y + a + b + c + d + e + f<CURSOR>
"#,
);
Expand Down
6 changes: 3 additions & 3 deletions crates/ty_python_semantic/src/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ mod implicit_globals {
{
return Place::Unbound.into();
}
let Type::ClassLiteral(module_type_class) = KnownClass::ModuleType.to_class_literal(db)
let Type::ClassSingleton(module_type_class) = KnownClass::ModuleType.to_class_singleton(db)
else {
return Place::Unbound.into();
};
Expand Down Expand Up @@ -1402,8 +1402,8 @@ mod implicit_globals {
#[salsa::tracked(returns(deref), heap_size=ruff_memory_usage::heap_size)]
fn module_type_symbols<'db>(db: &'db dyn Db) -> smallvec::SmallVec<[ast::name::Name; 8]> {
let Some(module_type) = KnownClass::ModuleType
.to_class_literal(db)
.into_class_literal()
.to_class_singleton(db)
.into_class_singleton()
else {
// The most likely way we get here is if a user specified a `--custom-typeshed-dir`
// without a `types.pyi` stub in the `stdlib/` directory
Expand Down
6 changes: 3 additions & 3 deletions crates/ty_python_semantic/src/semantic_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<'db> Completion<'db> {
| Type::Callable(_) => CompletionKind::Function,
Type::BoundMethod(_) | Type::MethodWrapper(_) => CompletionKind::Method,
Type::ModuleLiteral(_) => CompletionKind::Module,
Type::ClassLiteral(_) | Type::GenericAlias(_) | Type::SubclassOf(_) => {
Type::ClassSingleton(_) | Type::GenericAlias(_) | Type::SubclassOf(_) => {
CompletionKind::Class
}
// This is a little weird for "struct." I'm mostly interpreting
Expand Down Expand Up @@ -474,7 +474,7 @@ mod tests {
let model = SemanticModel::new(&db, foo);
let ty = class.inferred_type(&model);

assert!(ty.is_class_literal());
assert!(ty.is_class_singleton());

Ok(())
}
Expand All @@ -495,7 +495,7 @@ mod tests {
let model = SemanticModel::new(&db, bar);
let ty = alias.inferred_type(&model);

assert!(ty.is_class_literal());
assert!(ty.is_class_singleton());

Ok(())
}
Expand Down
Loading