Yeah the results were screenshots. Next time, i will just paste them as texts.
Still ‘unknown’ for any unidentified type (including ‘Any’ if not imported)
means it’s not identified as if you didn’t annotate the variable even though
you meant to say ‘Any’ type is ok there. That was my intention.
I still like the approach of doing `import typing as t` - (or other short
name of ones preference).
Bcause in the end, any argument used to bring "Any" as a built-in could be
used in favor
of any other element in typing anway.
Typing "t.Any, t.Union, t.Optional" is not a hassle and immediately
They pasted the code / results as screenshots.
But you got the gist.
In the future, it's really better to use plain text for email lists.
-CHB
On Tue, Dec 1, 2020 at 9:33 PM Steven D'Aprano wrote:
> On Mon, Nov 30, 2020 at 05:19:13PM +0400, Abdulla Al Kathiri wrote:
>
> > In python 3.9, I ge
On Mon, Nov 30, 2020 at 05:19:13PM +0400, Abdulla Al Kathiri wrote:
> In python 3.9, I get the following error:
>
>
> In python 3.10, I get no runtime errors:
>
>
>
>
Did you forget to paste the text? Or did gmail eat it?
> However, Pylance (I am not sure about mypy) didn’t recognize Any.
On Mon, Nov 30, 2020 at 4:27 PM Paul Bryan wrote:
>
> I believe the __future__ import makes any annotation a string, it doesn't
> make Any magically resolvable later. If you don't import Any into the scope
> of the annotation, it won't be resolved when getting type hints.
>
I don't say it works
imported from
> there as well.
>
> From: Paul Bryan
> Sent: 30 November 2020 06:30
> To: Steve Barnes ; Inada Naoki
> ; Abdulla Al Kathiri
>
> Cc: python-ideas
> Subject: Re: [Python-ideas] Re: Making "Any" a builtin
>
> pbryan@dynamo:~$ python3
&g
it is imported from there as well.
From: Paul Bryan
Sent: 30 November 2020 06:30
To: Steve Barnes ; Inada Naoki
; Abdulla Al Kathiri
Cc: python-ideas
Subject: Re: [Python-ideas] Re: Making "Any" a builtin
pbryan@dynamo<mailto:pbryan@dynamo>:~$ python3
Python 3.8.6 (default,
ot defined
>>>
On Mon, 2020-11-30 at 06:10 +, Steve Barnes wrote:
> Any only works as an annotation:
>
> In [3]: def fn(*argv: Any) -> Any:
> ...: return argv[0]
> ...:
>
>
> From: Paul Bryan
> Sent: 30 November 2020 05:55
> To: Inada
Any only works as an annotation:
In [3]: def fn(*argv: Any) -> Any:
...: return argv[0]
...:
From: Paul Bryan
Sent: 30 November 2020 05:55
To: Inada Naoki ; Abdulla Al Kathiri
Cc: python-ideas
Subject: [Python-ideas] Re: Making "Any" a builtin
pbryan@dynamo<mail
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 "", line 1, in
NameError: name 'Any' is not
Oh, note that Abdulla said: "we can annotate our **functions** with
“Any" right away without the extra step."
Python 3.9.0 (default, Nov 21 2020, 14:01:55)
>>> from __future__ import annotations
>>> def foo(a: Any, b: Dict[Any, Any]) -> Any: pass
--
Inada Naoki
Well, there are some exceptions. E.g. type aliases are still evaluated:
# Python 3.10
TT = tuple[int, Any]
Similarly, casts:
f(cast(Any, arg))
And subclassing from generic classes, e.g.
T = TypeVar("T")
class B(Generic[T]): ...
class C(B[Any]): ...
Probably some that I forgot.
On Sun, Nov 2
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/
Regards,
On Mon, Nov 30, 2020 at 12:29 AM Abdulla Al Kathiri
wrote:
>
> Instead of importing “Any" from t
13 matches
Mail list logo