On 9 Jan 2022 at 02:22:31, Steven D'Aprano <steve@pearwood.info> wrote:
On Sat, Jan 08, 2022 at 12:59:38AM +0100, jack.jansen@cwi.nl wrote:
I posted this suggestion earlier in the callable type syntax discussion, at which point it was completely ignored. Possibly because it’s a really stupid idea, but let me post it again on the off chance that it isn’t a stupid idea but was overlooked.

> If I can make a wild suggestion: why not create a little language
> for type specifications?

Any time we are tempted to prefix a question with "Why not ...", the
question is backwards. The right question is, "why should we ...".

Python is 30 years old and mature, with a HUGE ecosystem of users,
libraries, tooling, etc. It is far, far easier to get changes wrong than
to get them right, which is why we should be conservative when it comes
to language changes (including syntax). Changes to the language are
"default deny", not "default accept", and it is up to the proponents of
the change to prove their case, not for opponents to disprove it.

I agree 100% on these principles.

As a counter-argument, in this specific case, I’d say that the Python typing ecosystem is only ~5 years old and still evolving rapidly, so these principles apply with less force.

I personally believe that the syntax for type annotation doesn’t have, from the point of view of users, to be strictly Python, as long as it’s pythonic. 

I can sympathise with the idea of repurposing the regular Python syntax to describe types, and agree that it makes easier to bootstrap tools (typecheckers, IDEs…) but I think it has its limits in terms of expressivity, first. 

Second, I think willing to keep the same syntax constructs for the sake of lowering the cognitive burden of new developers is a red herring. These are two different languages, with entirely different semantics, and the links between them is not complement intuitive.

As an example (just for the sake of argument, I’m not proposing this kind of change) one could argue that 'list[int]’ doesn’t really relate to how lists are constructed or how the bracket operator is used in regular Python. A more intuitive construct (from this point of view) could have been ‘[int…]’. Same for dictionaries: ‘dict[int, str]’ vs. ‘{int: str}’ which looks closer that how dictionaries are constructed in Python.

  S.

--
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier - http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software - http://www.abilian.com/
Co-Founder & Co-Chairman, National Council for Free & Open Source Software (CNLL) - http://cnll.fr/
Co-Founder & Chairman, Association Professionnelle Européenne du Logiciel Libre (APELL) - https://www.apell.info/
Co-Founder & Spokesperson, European Cloud Industrial Alliance (EUCLIDIA) - https://www.euclidia.eu/ 
Founder, PyParis & PyData Paris - http://pyparis.org/http://pydata.fr/