Skip to content

Commit

Permalink
Extract is_override_method check
Browse files Browse the repository at this point in the history
Summary:
Instead of inlining the name of the override decorator
we support directly into typeCheck.ml, let's encode
it in a helper function of the Statement.Define module,
consistent with how we handle other special decorators
like `final`.

Reviewed By: kinto0

Differential Revision: D43055549

fbshipit-source-id: ca34452c739196f4e4f9feede216b88da8cb3ed5
  • Loading branch information
stroxler authored and facebook-github-bot committed Feb 9, 2023
1 parent 98d6773 commit 6e8dd15
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 1 addition & 3 deletions source/analysis/typeCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5347,9 +5347,7 @@ module State (Context : Context) = struct
errors
in
let check_override_decorator errors =
let override_decorator_name = "pyre_extensions.override" in
let has_override_decorator = StatementDefine.has_decorator define override_decorator_name in
if has_override_decorator then
if StatementDefine.is_override_method define then
match define with
| { Ast.Statement.Define.signature = { parent = Some parent; _ }; _ } -> (
let possibly_overridden_attribute =
Expand Down
8 changes: 8 additions & 0 deletions source/ast/statement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ and Define : sig

val is_final_method : t -> bool

val is_override_method : t -> bool

val is_class_method : t -> bool

val is_class_property : t -> bool
Expand Down Expand Up @@ -496,6 +498,8 @@ and Define : sig

val is_final_method : t -> bool

val is_override_method : t -> bool

val is_class_method : t -> bool

val is_class_property : t -> bool
Expand Down Expand Up @@ -661,6 +665,8 @@ end = struct

let is_final_method signature = has_decorator signature "typing.final"

let is_override_method signature = has_decorator signature "pyre_extensions.override"

let is_dunder_method signature =
let name = unqualified_name signature in
String.is_prefix ~prefix:"__" name && String.is_suffix ~suffix:"__" name
Expand Down Expand Up @@ -859,6 +865,8 @@ end = struct

let is_final_method { signature; _ } = Signature.is_final_method signature

let is_override_method { signature; _ } = Signature.is_override_method signature

let is_dunder_method { signature; _ } = Signature.is_dunder_method signature

let is_class_method { signature; _ } = Signature.is_class_method signature
Expand Down
4 changes: 4 additions & 0 deletions source/ast/statement.mli
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ and Define : sig

val is_final_method : t -> bool

val is_override_method : t -> bool

val is_class_method : t -> bool

val is_class_property : t -> bool
Expand Down Expand Up @@ -243,6 +245,8 @@ and Define : sig

val is_final_method : t -> bool

val is_override_method : t -> bool

val is_class_method : t -> bool

val is_class_property : t -> bool
Expand Down

0 comments on commit 6e8dd15

Please sign in to comment.