On Sat, Feb 05, 2022 at 11:21:48PM +0400, Abdulla Al Kathiri wrote:

> Hello all, 
> 
> Why can’t we use the literals directly as types? For example, 

Before suggesting a new feature, you should try it to see what it 
currently does.

>>> x: 1 | 2 | 3 = 4
>>> __annotations__
{'x': 3}

`1 | 2 | 3` already has a meaning as the bitwise-or of integers 1, 2, 3 
and so it evaluates to `3`. So backwards compatibility rules out 
changing the | operator meaning.

Other types don't support bitwise-or, and we don't want them to. E.g. 
bitwise-or of a string and None, or two strings, or a string and an int, 
should remain errors and not suddenly return a type object.

The bottom line here is that we cannot use literals as types because 
they aren't types, they are values, and the semantics of operations on 
types and operations on values are different.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LMKMTIOSU2ICBX7CNPU2LECVPDR3DFHQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to