I think this will go a long way toward making type annotations feel less like a tacked-on feature.
I think this will go a long way toward making type annotations feel less like a tacked-on feature.
Do you mean you'd been using that in comments?
Just to be clear, this isn't about ad-hoc syntaxes for use in comments, this is about syntax that parses when used in python code, and which can be used by type-checkers.
[int]
{str: int}
{'x': float, 'x': float}
are all valid python syntax, so e.g. these are all valid: def f(xs: [int]) -> {str: int}:
...
def g(x: 1+2+3, y: what('ever')) -> foo / bar:
...
it's just that tools like mypy won't be able to use that, because they expect a class or a `typing` type.i'm pretty sure you could even write a mypy plugin that'd interpret `[int]` into `list[int]` etc
In practice though we should probably all write annotations that do work with an existing type checker. False negatives are bad enough in mypy without people writing annotations for non-existent type checkers! (IMO --check-untyped-defs should always be used; mypy is misleading without it.)
oh, sure! "freeform annotations" that break mypy in a published library should be a punishable offense ;)