Complete support for Starlark type annotations (#1488)

This change introduces parsing, AST, formatting, and linting support for
experimental Bazel Starlark type annotations
(https://github.com/bazelbuild/bazel/issues/27370) and Buck2 type
syntax:

- Type alias statements (`type OptionalDict[T, U] = dict[T, U] | None`).
- Generic `def` statements (`def foo[T, U](x: T) -> U`).
- Var statements (`x: list[int]`)
- `type_*` AST nodes to cleanly distinguish type syntax from standard
expressions. In particular, this allows us to improve formatting for
complex type applications, and to allow the ellipsis (`...`) only in
type expressions.

Not supported yet: `cast` and `isinstance` expressions - these will be
added in a follow-up PR; supporting them is a bit tricky due to the
limitations of yacc's LALR(1) grammar.

Disclosure: Gemini-assisted.

TAG=agy
CONV=ae2ff586-d57d-4fd4-a22a-883aec5d0802

## Buildtools PR checklist

- [x] The code in this PR is covered by unit/integration tests.
- [x] I have tested these changes and provide testing instructions
below.
- [ ] I have either responded to, or resolved all Gemini comments on the
PR.
- [ ] I have read Google Eng Practices on [Small
Changes](https://google.github.io/eng-practices/review/developer/small-cls.html),
this PR either follows these guidelines or the description provides
reasoning for why they can not be followed.

@brandjon @susinmotion FYI
39 files changed
tree: 0df953ea646622018f5156bc035125d2951ccdef
  1. .bazelci/
  2. .github/
  3. api_proto/
  4. build/
  5. build_proto/
  6. buildifier/
  7. buildozer/
  8. bzlenv/
  9. config/
  10. convertast/
  11. deps_proto/
  12. differ/
  13. edit/
  14. extra_actions_base_proto/
  15. file/
  16. generatetables/
  17. labels/
  18. lang/
  19. release/
  20. tables/
  21. testutils/
  22. unused_deps/
  23. warn/
  24. wspace/
  25. .bazelrc
  26. .bazelversion
  27. .gitignore
  28. .mailmap
  29. .pre-commit-config.yaml
  30. BUILD.bazel
  31. CODEOWNERS
  32. CONTRIBUTING.md
  33. CONTRIBUTORS
  34. go.mod
  35. go.sum
  36. launcher.js
  37. LICENSE
  38. MODULE.bazel
  39. README.md
  40. status.py
  41. update_generated.sh
  42. WARNINGS.md
  43. WORKSPACE
  44. WORKSPACE.bzlmod
README.md

Buildtools for bazel

This repository contains developer tools for working with Google's bazel buildtool.

Build status

Setup

See instructions in each tool's directory.