Skip to content

Commit 95497ff

Browse files
authored
[ty] Fix panic when trying to pull types for attribute expressions inside Literal type expressions (#18535)
1 parent b3b900d commit 95497ff

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from typing import Literal
2+
3+
class Format:
4+
STRING = "string"
5+
6+
def evaluate(format: Literal[Format.STRING]) -> str: ...

crates/ty_project/tests/check.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,18 +304,14 @@ const KNOWN_FAILURES: &[(&str, bool, bool)] = &[
304304

305305
// These are all "expression should belong to this TypeInference region and TypeInferenceBuilder should have inferred a type for it"
306306
("crates/ty_vendored/vendor/typeshed/stdlib/abc.pyi", true, true),
307-
("crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi", true, true),
308307
("crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi", true, true),
309308
("crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi", true, true),
310309
("crates/ty_vendored/vendor/typeshed/stdlib/curses/__init__.pyi", true, true),
311-
("crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi", true, true),
312-
("crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi", true, true),
313310
("crates/ty_vendored/vendor/typeshed/stdlib/lzma.pyi", true, true),
314311
("crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi", true, true),
315312
("crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi", true, true),
316313
("crates/ty_vendored/vendor/typeshed/stdlib/pathlib/types.pyi", true, true),
317314
("crates/ty_vendored/vendor/typeshed/stdlib/pstats.pyi", true, true),
318-
("crates/ty_vendored/vendor/typeshed/stdlib/signal.pyi", true, true),
319315
("crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi", true, true),
320316
("crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi", true, true),
321317
("crates/ty_vendored/vendor/typeshed/stdlib/tempfile.pyi", true, true),

crates/ty_python_semantic/src/types/infer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9468,11 +9468,13 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
94689468
ast::Expr::Attribute(ast::ExprAttribute { value, attr, .. }) => {
94699469
let value_ty = self.infer_expression(value);
94709470
// TODO: Check that value type is enum otherwise return None
9471-
value_ty
9471+
let ty = value_ty
94729472
.member(self.db(), &attr.id)
94739473
.place
94749474
.ignore_possibly_unbound()
9475-
.unwrap_or(Type::unknown())
9475+
.unwrap_or(Type::unknown());
9476+
self.store_expression_type(parameters, ty);
9477+
ty
94769478
}
94779479
// for negative and positive numbers
94789480
ast::Expr::UnaryOp(u)

0 commit comments

Comments
 (0)