The __future__ import only makes the Any type available for use during
**annotations** i.e. if you follow the below with:
In [6]: from typing import Any
In [7]: get_type_hints(fn)
Out[7]: {'argv': typing.Any, 'return': typing.Any}
So the Any is out of scope for typing unless it is imported from there as well.
From: Paul Bryan <[email protected]>
Sent: 30 November 2020 06:30
To: Steve Barnes <[email protected]>; Inada Naoki
<[email protected]>; Abdulla Al Kathiri <[email protected]>
Cc: python-ideas <[email protected]>
Subject: Re: [Python-ideas] Re: Making "Any" a builtin
pbryan@dynamo<mailto:pbryan@dynamo>:~$ python3
Python 3.8.6 (default, Sep 30 2020, 04:00:38)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import annotations
>>> def fn(*argv: Any) -> Any:
... ...
...
>>> from typing import get_type_hints
>>> get_type_hints(fn)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/typing.py", line 1264, in get_type_hints
value = _eval_type(value, globalns, localns)
File "/usr/lib/python3.8/typing.py", line 270, in _eval_type
return t._evaluate(globalns, localns)
File "/usr/lib/python3.8/typing.py", line 518, in _evaluate
eval(self.__forward_code__, globalns, localns),
File "<string>", line 1, in <module>
NameError: name 'Any' is not defined
>>>
On Mon, 2020-11-30 at 06:10 +0000, Steve Barnes wrote:
Any only works as an annotation:
In [3]: def fn(*argv: Any) -> Any:
...: return argv[0]
...:
From: Paul Bryan <[email protected]<mailto:[email protected]>>
Sent: 30 November 2020 05:55
To: Inada Naoki <[email protected]<mailto:[email protected]>>;
Abdulla Al Kathiri
<[email protected]<mailto:[email protected]>>
Cc: python-ideas <[email protected]<mailto:[email protected]>>
Subject: [Python-ideas] Re: Making "Any" a builtin
pbryan@dynamo<mailto:pbryan@dynamo>:~$ python3
Python 3.8.6 (default, Sep 30 2020, 04:00:38)
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import annotations
>>> Any
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Any' is not defined
>>>
On Mon, 2020-11-30 at 14:43 +0900, Inada Naoki wrote:
Since Python 3.10, you can use "Any" without "from typing import Any".
You can do it in Python 3.7 by "from __future__ import annotations" too.
See
https://www.python.org/dev/peps/pep-0563/<https://eur05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.python.org%2Fdev%2Fpeps%2Fpep-0563%2F&data=04%7C01%7C%7Cf27001db4fda41a8422008d894f63854%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637423132705057013%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=QKqmO0f%2BLE040QGySslUfYKGGjyVPIbqVndWLwLHEe4%3D&reserved=0>
Regards,
On Mon, Nov 30, 2020 at 12:29 AM Abdulla Al Kathiri
<[email protected]<mailto:[email protected]>> wrote:
Instead of importing “Any" from the typing module, we can annotate our
functions with “Any" right away without the extra step. What do you think? We
have the builtin function “any” which some Python users could mistakingly use,
but static type checkers should catch that.
_______________________________________________
Python-ideas mailing list --
[email protected]<mailto:[email protected]>
To unsubscribe send an email to
[email protected]<mailto:[email protected]>
https://mail.python.org/mailman3/lists/python-ideas.python.org/<https://eur05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman3%2Flists%2Fpython-ideas.python.org%2F&data=04%7C01%7C%7Cf27001db4fda41a8422008d894f63854%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637423132705057013%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=H%2BrsVsj%2BgLzD0JEROxT8tZb%2Bgn6zua0Hc%2BBCsm%2Fo%2FE4%3D&reserved=0>
Message archived at
https://mail.python.org/archives/list/[email protected]/message/ELI474TKP2OKHP4NW5HOVUPKDPLYE2JP/<https://eur05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Farchives%2Flist%2Fpython-ideas%40python.org%2Fmessage%2FELI474TKP2OKHP4NW5HOVUPKDPLYE2JP%2F&data=04%7C01%7C%7Cf27001db4fda41a8422008d894f63854%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637423132705057013%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=fTeCdpijNUBREFSHnA%2FYqD0dkEUq0g48xVHjiYCUMHc%3D&reserved=0>
Code of Conduct:
http://python.org/psf/codeofconduct/<https://eur05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F&data=04%7C01%7C%7Cf27001db4fda41a8422008d894f63854%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637423132705067008%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=FHpZxOJuTA6gUkhUqwkbtZP05jBTrRliCDAG%2BfOzwyo%3D&reserved=0>
--
Inada Naoki <[email protected]<mailto:[email protected]>>
_______________________________________________
Python-ideas mailing list --
[email protected]<mailto:[email protected]>
To unsubscribe send an email to
[email protected]<mailto:[email protected]>
https://mail.python.org/mailman3/lists/python-ideas.python.org/<https://eur05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman3%2Flists%2Fpython-ideas.python.org%2F&data=04%7C01%7C%7Cf27001db4fda41a8422008d894f63854%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637423132705067008%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=gBFYebL5JU%2BF0R1xo4c1Ynn6WbX0CiJtgFsomRFkLcg%3D&reserved=0>
Message archived at
https://mail.python.org/archives/list/[email protected]/message/VENGRL6T54XQUYDXONZRZE7LUCO6MKWI/<https://eur05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Farchives%2Flist%2Fpython-ideas%40python.org%2Fmessage%2FVENGRL6T54XQUYDXONZRZE7LUCO6MKWI%2F&data=04%7C01%7C%7Cf27001db4fda41a8422008d894f63854%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637423132705077002%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=iCFcrLAsqsph9RfW%2BcybewCKo76feAs6Y0haKRmi6%2FY%3D&reserved=0>
Code of Conduct:
http://python.org/psf/codeofconduct/<https://eur05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F&data=04%7C01%7C%7Cf27001db4fda41a8422008d894f63854%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637423132705077002%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=%2F7zbYkgPIZg1rpyFnSbRjyk5%2Fxyv0ByZPD6MUstQ6EM%3D&reserved=0>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/C3MADOUNVJEPUVRGQTUCAYUCLQPEBCKY/
Code of Conduct: http://python.org/psf/codeofconduct/