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
Add isinstance keyword, and allow isinstance(x,t) to be parsed - but not resolved
Note that we parse arbitrary type expressions on the RHS of isinstance, but
will be planning to limit the allowed types when resolving (in a follow-up).
Consider, for example, something like isinstance(x, list[int]) - we cannot
allow it because x may subsequently get a non-int element added to it.
By contrast, we may want to allow e.g. `isinstance(f, Callable[[str], bool])`
to test if f is a predicate on a string (note that Python doesn't, but in
Python this is an eval-time error, not a syntax error). And further consider
the possibility of `isinstance(x, T)` - where `T` is a type alias (and which
might well be an alias for something we don't want to allow). So we cannot
take the simple path of syntactically allowing only identifiers.
Also make a drive-by fix to `cast()`'s pretty-printer.
Working towards bazelbuild#27372 and isinstance().
PiperOrigin-RevId: 829638719
Change-Id: Iad1c4307fb4da262031b5e664f846662a081c210
0 commit comments