Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google sync #639

Merged
merged 4 commits into from
Aug 4, 2020
Merged

Google sync #639

merged 4 commits into from
Aug 4, 2020

Conversation

rchen152
Copy link
Contributor

@rchen152 rchen152 commented Aug 4, 2020

No description provided.

martindemello and others added 4 commits August 4, 2020 14:39
This currently only works within a file; in the following code:

  Foo = Union[T, List[T]]
  x: Foo[int]

the generated pyi code will contain

  Foo = Any
  x: Union[int, List[int]]

that is, concrete instantiations of the alias will be correctly used and
exported, but the alias itself will not be exported.

PiperOrigin-RevId: 324293324
The CL to support Union type macros caused a bizarre bug where
Union.set_slot('__getitem__') calls getattribute(Union, '__getitem__'),
creating an extra node, causing convert_class_annotations for a tuple
annotation containing a forward referenced imported type to be evaluated at the
wrong node, leading to the generation of an extra late annotation for the
imported module, finally producing "Invalid type annotation '<instance of
module>': Not a type" errors all over the place for pb2 enum annotations, since
those always have to be quoted. I resolved this by special-casing
Union.__getitem__ in attribute.py, so the extra node is not generated.

I also noticed that the type macro CL produced a corner case where
Union.getitem_slot is indistinguishable from calling __getitem__ on a Union's
options when a value is annotated as Type[Union[C1, C2, ...]] (but *not* when
the annotation is Union[Type[C1], Type[C2], ...]!). The inferred type is still
correct, if imprecise, so I just documented this behavior in a test rather than
trying to fix it.

PiperOrigin-RevId: 324684760
@google-cla google-cla bot added the cla: yes label Aug 4, 2020
@rchen152 rchen152 merged commit 2d8c896 into master Aug 4, 2020
@rchen152 rchen152 deleted the google_sync branch August 4, 2020 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants