Skip to content

Commit 4c68c23

Browse files
mrkmndzfacebook-github-bot
authored andcommitted
Include GenericMeta unconditionally
Summary: PEP 560 removed `typing.GenericMeta`, so it was conditionally removed from typeshed by python/typeshed#3933 . However, we rely on that class to be the metaclass of `Generic`, all generic classes, and all protocols. This meant that once typeshed was updated, lots of attributes disappeared. This diff fixes that by special casing it back in. This means we'll erroneously allow users to refer to it, but that's fine for now. Reviewed By: grievejia Differential Revision: D21854250 fbshipit-source-id: 294740a866800b70939f425e8919a3c275b36285
1 parent c98f191 commit 4c68c23

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

analysis/unannotatedGlobalEnvironment.ml

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,36 @@ let missing_builtin_classes, missing_typing_classes, missing_typing_extensions_c
735735
]
736736
|> List.map ~f:Node.create_with_default_location
737737
in
738+
let generic_meta_body =
739+
[
740+
Statement.Define
741+
{
742+
signature =
743+
{
744+
name =
745+
Reference.create "typing.GenericMeta.__getitem__"
746+
|> Node.create_with_default_location;
747+
parameters =
748+
[
749+
{ Parameter.name = "cls"; value = None; annotation = None }
750+
|> Node.create_with_default_location;
751+
{ Parameter.name = "arg"; value = None; annotation = None }
752+
|> Node.create_with_default_location;
753+
];
754+
decorators = [];
755+
return_annotation = None;
756+
async = false;
757+
generator = false;
758+
parent = Some (Reference.create "typing.GenericMeta");
759+
nesting_define = None;
760+
};
761+
captures = [];
762+
unbound_names = [];
763+
body = [];
764+
}
765+
|> Node.create_with_default_location;
766+
]
767+
in
738768

739769
let typing_classes =
740770
[
@@ -750,6 +780,7 @@ let missing_builtin_classes, missing_typing_classes, missing_typing_extensions_c
750780
make ~metaclasses:[Primitive "typing.GenericMeta"] "typing.Generic";
751781
make "typing.ClassMethod" ~bases:single_unary_generic ~body:classmethod_body;
752782
make "typing.StaticMethod" ~bases:single_unary_generic ~body:staticmethod_body;
783+
make "typing.GenericMeta" ~bases:[Primitive "type"] ~body:generic_meta_body;
753784
]
754785
in
755786
let typing_extension_classes =
@@ -818,38 +849,6 @@ let register_class_definitions ({ Source.source_path = { SourcePath.qualifier; _
818849
Type.expression (Type.parametric "typing.Generic" [Single (Type.variable "typing._T")])
819850
in
820851
{ definition with Class.bases = [{ name = None; value }] }
821-
| "typing.GenericMeta" ->
822-
let body =
823-
[
824-
Statement.Define
825-
{
826-
signature =
827-
{
828-
name =
829-
Reference.create "typing.GenericMeta.__getitem__"
830-
|> Node.create_with_default_location;
831-
parameters =
832-
[
833-
{ Parameter.name = "cls"; value = None; annotation = None }
834-
|> Node.create_with_default_location;
835-
{ Parameter.name = "arg"; value = None; annotation = None }
836-
|> Node.create_with_default_location;
837-
];
838-
decorators = [];
839-
return_annotation = None;
840-
async = false;
841-
generator = false;
842-
parent = Some (Reference.create "typing.GenericMeta");
843-
nesting_define = None;
844-
};
845-
captures = [];
846-
unbound_names = [];
847-
body = [];
848-
}
849-
|> Node.create_with_default_location;
850-
]
851-
in
852-
{ definition with body }
853852
| _ -> definition
854853
in
855854
WriteOnly.set_class_definition

test/test.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,8 @@ let typeshed_stubs ?(include_helper_builtins = true) () =
943943
ClassVar: _SpecialForm = ...
944944
NoReturn: _SpecialForm = ...
945945
946-
class GenericMeta(type): ...
946+
if sys.version_info < (3, 7):
947+
class GenericMeta(type): ...
947948
948949
@runtime
949950
class Sized(Protocol, metaclass=ABCMeta):

0 commit comments

Comments
 (0)