Skip to content

Commit

Permalink
Fix ClassDef/ClassType mismatch causing assert_type failures
Browse files Browse the repository at this point in the history
Reviewed By: ndmitchell

Differential Revision: D67764061

fbshipit-source-id: 05e0c6dfc8d541144e62bc8f658062330daff875
  • Loading branch information
rchen152 authored and facebook-github-bot committed Jan 2, 2025
1 parent f16d823 commit 2c6ddb3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 42 deletions.
40 changes: 10 additions & 30 deletions pyre2/conformance/third_party/conformance.exp
Original file line number Diff line number Diff line change
Expand Up @@ -9537,8 +9537,8 @@
{
"code": -2,
"column": 1,
"concise_description": "assert_type(type[NoNonDefaults], type[NoNonDefaults[str, int]]) failed",
"description": "assert_type(type[NoNonDefaults], type[NoNonDefaults[str, int]]) failed",
"concise_description": "assert_type(type[NoNonDefaults[Error, Error]], type[NoNonDefaults[str, int]]) failed",
"description": "assert_type(type[NoNonDefaults[Error, Error]], type[NoNonDefaults[str, int]]) failed",
"line": 30,
"name": "PyreError",
"stop_column": 58,
Expand All @@ -9547,8 +9547,8 @@
{
"code": -2,
"column": 1,
"concise_description": "assert_type(type[AllTheDefaults], type[AllTheDefaults[Any, Any, str, int, bool]]) failed",
"description": "assert_type(type[AllTheDefaults], type[AllTheDefaults[Any, Any, str, int, bool]]) failed",
"concise_description": "assert_type(type[AllTheDefaults[Error, Error, Error, Error, Error]], type[AllTheDefaults[Any, Any, str, int, bool]]) failed",
"description": "assert_type(type[AllTheDefaults[Error, Error, Error, Error, Error]], type[AllTheDefaults[Any, Any, str, int, bool]]) failed",
"line": 45,
"name": "PyreError",
"stop_column": 76,
Expand All @@ -9574,16 +9574,6 @@
"stop_column": 39,
"stop_line": 76
},
{
"code": -2,
"column": 1,
"concise_description": "assert_type(type[Class_ParamSpec], type[Class_ParamSpec]) failed",
"description": "assert_type(type[Class_ParamSpec], type[Class_ParamSpec]) failed",
"line": 79,
"name": "PyreError",
"stop_column": 62,
"stop_line": 79
},
{
"code": -2,
"column": 35,
Expand Down Expand Up @@ -9644,16 +9634,6 @@
"stop_column": 44,
"stop_line": 91
},
{
"code": -2,
"column": 1,
"concise_description": "assert_type(type[Class_TypeVarTuple], type[Class_TypeVarTuple]) failed",
"description": "assert_type(type[Class_TypeVarTuple], type[Class_TypeVarTuple]) failed",
"line": 94,
"name": "PyreError",
"stop_column": 76,
"stop_line": 94
},
{
"code": -2,
"column": 38,
Expand Down Expand Up @@ -9879,8 +9859,8 @@
{
"code": -2,
"column": 1,
"concise_description": "assert_type(type[slice], type[slice[int, int, int | None]]) failed",
"description": "assert_type(type[slice], type[slice[int, int, int | None]]) failed",
"concise_description": "assert_type(type[slice[Error, Error, Error]], type[slice[int, int, int | None]]) failed",
"description": "assert_type(type[slice[Error, Error, Error]], type[slice[int, int, int | None]]) failed",
"line": 23,
"name": "PyreError",
"stop_column": 54,
Expand Down Expand Up @@ -9939,8 +9919,8 @@
{
"code": -2,
"column": 1,
"concise_description": "assert_type(type[Bar], type[Bar[Any, list[Any]]]) failed",
"description": "assert_type(type[Bar], type[Bar[Any, list[Any]]]) failed",
"concise_description": "assert_type(type[Bar[Error, Error]], type[Bar[Any, list[Any]]]) failed",
"description": "assert_type(type[Bar[Error, Error]], type[Bar[Any, list[Any]]]) failed",
"line": 94,
"name": "PyreError",
"stop_column": 44,
Expand Down Expand Up @@ -9991,8 +9971,8 @@
{
"code": -2,
"column": 1,
"concise_description": "assert_type(type[Bar], type[Bar[str]]) failed",
"description": "assert_type(type[Bar], type[Bar[str]]) failed",
"concise_description": "assert_type(type[Bar[Error]], type[Bar[str]]) failed",
"description": "assert_type(type[Bar[Error]], type[Bar[str]]) failed",
"line": 45,
"name": "PyreError",
"stop_column": 33,
Expand Down
14 changes: 7 additions & 7 deletions pyre2/conformance/third_party/conformance.result
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,14 @@
"generics_defaults.py": [
"Line 104: Expected 1 errors",
"Line 111: Expected 1 errors",
"Line 30: Unexpected errors ['assert_type(type[NoNonDefaults], type[NoNonDefaults[str, int]]) failed']",
"Line 45: Unexpected errors ['assert_type(type[AllTheDefaults], type[AllTheDefaults[Any, Any, str, int, bool]]) failed']",
"Line 30: Unexpected errors ['assert_type(type[NoNonDefaults[Error, Error]], type[NoNonDefaults[str, int]]) failed']",
"Line 45: Unexpected errors ['assert_type(type[AllTheDefaults[Error, Error, Error, Error, Error]], type[AllTheDefaults[Any, Any, str, int, bool]]) failed']",
"Line 76: Unexpected errors ['untype, got ParamSpec']",
"Line 79: Unexpected errors ['assert_type(type[Class_ParamSpec], type[Class_ParamSpec]) failed', 'Expected 0 type arguments for class `Class_ParamSpec`, got 2.']",
"Line 79: Unexpected errors ['Expected 0 type arguments for class `Class_ParamSpec`, got 2.']",
"Line 80: Unexpected errors ['Expected 0 type arguments for class `Class_ParamSpec`, got 2.']",
"Line 81: Unexpected errors ['Expected 0 type arguments for class `Class_ParamSpec`, got 1.', 'untype, got list[type[bool]]', 'Expected 0 type arguments for class `Class_ParamSpec`, got 2.']",
"Line 91: Unexpected errors ['TODO: Starred(ExprStarred - Answers::expr_infer']",
"Line 94: Unexpected errors ['assert_type(type[Class_TypeVarTuple], type[Class_TypeVarTuple]) failed', 'Expected 0 type arguments for class `Class_TypeVarTuple`, got 1.', 'TODO: Starred(ExprStarred - Answers::expr_infer']",
"Line 94: Unexpected errors ['Expected 0 type arguments for class `Class_TypeVarTuple`, got 1.', 'TODO: Starred(ExprStarred - Answers::expr_infer']",
"Line 95: Unexpected errors ['Expected 0 type arguments for class `Class_TypeVarTuple`, got 2.']",
"Line 96: Unexpected errors ['Expected 0 type arguments for class `Class_TypeVarTuple`, got 2.', 'Expected 0 type arguments for class `Class_TypeVarTuple`, got 2.']",
"Line 127: Unexpected errors ['assert_type(Any, int) failed']",
Expand All @@ -699,18 +699,18 @@
"Line 68: Expected 1 errors",
"Line 74: Expected 1 errors",
"Line 78: Expected 1 errors",
"Line 23: Unexpected errors ['assert_type(type[slice], type[slice[int, int, int | None]]) failed']",
"Line 23: Unexpected errors ['assert_type(type[slice[Error, Error, Error]], type[slice[int, int, int | None]]) failed']",
"Line 24: Unexpected errors ['assert_type(slice[Any, Any, Any], slice[int, int, int | None]) failed']",
"Line 25: Unexpected errors ['assert_type(slice[str, TypeVar[StartT], int | None], slice[str, str, int | None]) failed']",
"Line 94: Unexpected errors ['assert_type(type[Bar], type[Bar[Any, list[Any]]]) failed']",
"Line 94: Unexpected errors ['assert_type(type[Bar[Error, Error]], type[Bar[Any, list[Any]]]) failed']",
"Line 95: Unexpected errors ['assert_type(type[Bar[int, list[TypeVar[Z1]]]], type[Bar[int, list[int]]]) failed']",
"Line 96: Unexpected errors ['assert_type(Bar[int, list[TypeVar[Z1]]], Bar[int, list[int]]) failed']"
],
"generics_defaults_specialization.py": [
"Line 30: Expected 1 errors",
"Line 25: Unexpected errors ['untype, got Forall[DefaultStrT, LegacyExplicitTypeAlias[MyAlias, type[SomethingWithNoDefaults[int, DefaultStrT]]]]']",
"Line 26: Unexpected errors ['assert_type(Any, SomethingWithNoDefaults[int, str]) failed']",
"Line 45: Unexpected errors ['assert_type(type[Bar], type[Bar[str]]) failed']",
"Line 45: Unexpected errors ['assert_type(type[Bar[Error]], type[Bar[str]]) failed']",
"Line 46: Unexpected errors ['assert_type(Bar[Any], Bar[str]) failed']"
],
"generics_paramspec_basic.py": [
Expand Down
5 changes: 4 additions & 1 deletion pyre2/pyre2/bin/alt/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,10 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
let expr_b = &x.arguments.args[1];
let a = self.expr_infer(expr_a);
let b = self.expr_untype(expr_b);
let a = self.solver().deep_force(a).explicit_any();
let a = self.canonicalize_all_class_types(
self.solver().deep_force(a).explicit_any(),
expr_a.range(),
);
let b = self.canonicalize_all_class_types(
self.solver().deep_force(b).explicit_any(),
expr_b.range(),
Expand Down
6 changes: 2 additions & 4 deletions pyre2/pyre2/bin/test/narrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

use crate::testcase;
use crate::testcase_with_bug;

testcase!(
test_is,
Expand All @@ -31,16 +30,15 @@ def f(x: str | None):
"#,
);

// TODO: fix the assert_type bug that is causing this assertion to fail.
testcase_with_bug!(
testcase!(
test_is_subtype,
r#"
from typing import assert_type
class A: pass
class B(A): pass
def f(x: type[A]):
if x is B:
assert_type(x, type[B]) # E: assert_type(type[B], type[B]) failed
assert_type(x, type[B])
"#,
);

Expand Down
9 changes: 9 additions & 0 deletions pyre2/pyre2/bin/test/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,3 +1031,12 @@ def f(x: int):
assert_type(y, int)
"#,
);

testcase!(
test_type_of_class,
r#"
from typing import assert_type
class A: pass
assert_type(A, type[A])
"#,
);

0 comments on commit 2c6ddb3

Please sign in to comment.