Title: Alternative type-first annotation syntax: type: name = value
Body:
Summary
I’d like to propose an alternative syntax for variable type annotations where the type precedes the variable name, as an optional complement to PEP 526’s existing
name: type = valueform:str: name = "Laura" int: age = 20 float: height = 1.90 bool: is_developer = TrueThis would be semantically identical to today’s:
name: str = "Laura" age: int = 20 height: float = 1.90 is_developer: bool = TrueMotivation
Developers coming from C, Java, or Go are used to reading the type first when scanning a declaration (
String name = "Laura";). Putting the type first could make declarations easier to scan visually, especially in code with many annotated variables, and could make columns of type-aligned declarations easier to skim in editors.Known problems I’m aware of
- This directly conflicts with PEP 20 (“There should be one — and preferably only one — obvious way to do it”). I’d like to hear whether the community thinks the readability gain is worth having two syntaxes for the same thing.
- There’s a real grammar ambiguity concern: a statement starting with
str: namecould be confused with a dict literal key ({str: name}) or other existing uses of:in expression context. I haven’t worked out whether this is resolvable without breaking existing valid code — happy to hear from people who know the CPython grammar/parser better than I do.- Tooling cost: black, ruff, mypy, pylint, and every IDE would need to support both forms, which could fragment style across the ecosystem.
Alternatives already considered
- Just using formatters (black/ruff) to visually align existing PEP 526 annotations instead of changing syntax.
- Implementing this as a linter/formatter plugin or stub-file convention rather than a runtime/grammar change.
I’m posting here first (rather than drafting a full PEP) specifically to get feedback on whether this is worth pursuing further, and especially on the grammar ambiguity issue. Genuinely open to being told this isn’t a good idea — I’d rather find that out here than after writing a full PEP.