Skip to content

Commit

Permalink
exclude enum _value_ from uninitialized attribute error
Browse files Browse the repository at this point in the history
Summary:
per Eric's comment in python/typing#1804 (comment)

_value_ is magic for enums, and we shouldn't give uninitialized attr errors for it

Reviewed By: migeed-z

Differential Revision: D59833300

fbshipit-source-id: 59391ee56aecbab8b648648d27927258b2b6d3fc
  • Loading branch information
yangdanny97 authored and facebook-github-bot committed Jul 17, 2024
1 parent c3aa06d commit 6065e71
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions source/analysis/typeCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7585,20 +7585,24 @@ let emit_errors_on_exit (module Context : Context) ~errors_sofar ~resolution ()
->
let parent = Type.Primitive (ClassSummary.name definition |> Reference.show) in
let expected = annotation in
let is_enum =
GlobalResolution.less_or_equal
global_resolution
~left:parent
~right:Type.enumeration
in
if Type.is_top expected then
None
else if is_enum && String.equal name "_value_" then
(* _value_ is automatically initialized for enums *)
None
else
let error_kind =
if is_protocol then
Error.Protocol (Reference.create original_class_name)
else if is_abstract then
Error.Abstract (Reference.create original_class_name)
else if
GlobalResolution.less_or_equal
global_resolution
~left:parent
~right:Type.enumeration
then
else if is_enum then
Error.Enumeration
else
Error.Class
Expand Down

0 comments on commit 6065e71

Please sign in to comment.