You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 25, 2026. It is now read-only.
annotations subscripting containers cause TypeErrors #1607
As per an internal doc, subscripting a container that does not inherit from typing.Generic can cause errors. In particular, a MutableSequence indexed by enums causes an error of the form TypeError: Parameters to generic types must be types. This can be triggered, for example, by code of the form
which we are seeing in the internal part of our publishing pipeline.
Either of these fixes by itself works:
Quoting the type: MutableSequence['dayofweek_pb2.DayOfWeek']
Adding from __future__ import annotations at the top of the file. As per an internal reference, this seems to be related to PEP563, which has a status of Accepted as of 2017, so it's not clear why we would need a fix in the first place.
Apparently PEP 563 was rolled back from Python3.10: See this Reddit discussion and Python.org discussion, which say that due to compatibility concerns, making PEP563 be the default will not happen until Python3.11.
Reading more about "future statements" in the doc, it seems that "All historical features enabled by the future statement are still recognized by Python 3" and are "only kept for backwards compatibility", so presumably this policy will continue to be the case in the future. In that case, the future statement solution seems like a correct and easy fix that won't in itself incur future maintenance.
(Also if interest: PEP 236 which proposed the __future_ imports.)
Activity
atulep commentedon Feb 22, 2023
looks reasonable.
vchudnov-g commentedon Feb 23, 2023
Apparently PEP 563 was rolled back from Python3.10: See this Reddit discussion and Python.org discussion, which say that due to compatibility concerns, making PEP563 be the default will not happen until Python3.11.
vchudnov-g commentedon Feb 23, 2023
Reading more about "future statements" in the doc, it seems that "All historical features enabled by the future statement are still recognized by Python 3" and are "only kept for backwards compatibility", so presumably this policy will continue to be the case in the future. In that case, the future statement solution seems like a correct and easy fix that won't in itself incur future maintenance.
(Also if interest: PEP 236 which proposed the
__future_imports.)WIP: Add FAILING tests for type errors caused by enums in containers
fix: Resolve errors from annotating containers with non-local enums (#…
fix: Resolve errors from annotating containers with non-local enums (#…