Skip to content

Commit

Permalink
Exclude the __init__ method from being considered in variance inference
Browse files Browse the repository at this point in the history
Summary: I was only excluding __init__ from being included in variance in one of the cases. We need to exclude any attribute called __init__ from variance

Reviewed By: samwgoldman

Differential Revision: D64857404

fbshipit-source-id: f66124c0a0fdc9e2e5c932f32990e3e89b5de7cb
  • Loading branch information
migeed-z authored and facebook-github-bot committed Oct 25, 2024
1 parent fca57a9 commit 2b0daad
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
5 changes: 2 additions & 3 deletions source/analysis/attributeResolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ module VarianceVisitor = struct
List.iter
~f:(fun x ->
let element = AnnotatedAttribute.uninstantiated_annotation x in
begin
if not (String.equal (AnnotatedAttribute.name x) "__init__") then begin
match element with
| { AnnotatedAttribute.UninstantiatedAnnotation.kind = Attribute annotation; _ } ->
let visibility = AnnotatedAttribute.visibility x in
Expand All @@ -185,8 +185,7 @@ module VarianceVisitor = struct
DecoratedMethod { undecorated_signature; _ };
_;
} ->
if not (String.equal (AnnotatedAttribute.name x) "__init__") then
on_type ~variance:Covariant ~inj:true ~typ:(Type.Callable undecorated_signature)
on_type ~variance:Covariant ~inj:true ~typ:(Type.Callable undecorated_signature)
| { AnnotatedAttribute.UninstantiatedAnnotation.kind = Property { getter; setter }; _ }
-> (
let call_on_type_co value =
Expand Down
6 changes: 0 additions & 6 deletions source/analysis/test/integration/typeVariableTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ let test_type_variable_scoping =
"Incompatible variable type [9]: vinv5_1 is declared to have type \
`ShouldBeInvariant5[float]` but is used as type `ShouldBeInvariant5[int]`.";
];
(* TODO migeedz: In both of these tests, vo4_1 should be okay. Is there something about the
generated attributes that's causing this? *)
labeled_test_case __FUNCTION__ __LINE__
@@ assert_type_errors
{|
Expand All @@ -346,8 +344,6 @@ let test_type_variable_scoping =
|}
[
"Incompatible variable type [9]: vo4_1 is declared to have type \
`ShouldBeCovariant4[float]` but is used as type `ShouldBeCovariant4[int]`.";
"Incompatible variable type [9]: vo4_4 is declared to have type \
`ShouldBeCovariant4[int]` but is used as type `ShouldBeCovariant4[float]`.";
];
Expand All @@ -367,8 +363,6 @@ let test_type_variable_scoping =
|}
[
"Incompatible variable type [9]: vo4_1 is declared to have type \
`ShouldBeCovariant4[float]` but is used as type `ShouldBeCovariant4[int]`.";
"Incompatible variable type [9]: vo4_4 is declared to have type \
`ShouldBeCovariant4[int]` but is used as type `ShouldBeCovariant4[float]`.";
];
Expand Down

0 comments on commit 2b0daad

Please sign in to comment.