[issue42786] Different repr for collections.abc.Callable and typing.Callable

2020-12-30 Thread Svyatoslav


Svyatoslav  added the comment:

Thanks a lot! I am closing this issue.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42786] Different repr for collections.abc.Callable and typing.Callable

2020-12-30 Thread Ken Jin


Ken Jin  added the comment:

You're welcome, and yes you're right! You can read the news item for it here 
https://docs.python.org/3/whatsnew/3.9.html#notable-changes-in-python-3-9-2. 

The expected release date for Python 3.9.2 is Monday, 2021-02-15 according to 
PEP 596 https://www.python.org/dev/peps/pep-0596/.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42786] Different repr for collections.abc.Callable and typing.Callable

2020-12-30 Thread Svyatoslav


Svyatoslav  added the comment:

Ok, thanks for the answer. Did I understand correctly that the issue will be 
fixed in 3.9.2 as well?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42786] Different repr for collections.abc.Callable and typing.Callable

2020-12-30 Thread Ken Jin


Ken Jin  added the comment:

This was addressed in issue42195 and issue40494 as you pointed out :). It has 
been fixed in Python 3.10. Unfortunately the backport didn't make it in time 
for Python 3.9.1, and will come in Python 3.9.2 instead. Sadly there's not much 
to do about that.

On 3.10:

>>> import collections
>>> repr(collections.abc.Callable[[int], str])
'collections.abc.Callable[[int], str]'

--
nosy: +kj

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42786] Different repr for collections.abc.Callable and typing.Callable

2020-12-30 Thread Svyatoslav


New submission from Svyatoslav :

Was making some typing conversions to string and noticed a different behavior 
of collections.abc.Callable and typing.Callable here in 3.9.1. Issues 
issue42195 and issue40494 can be related.

>>> import collections, typing
>>> repr(collections.abc.Callable[[int], str])
"collections.abc.Callable[[], str]"
>>> repr(typing.Callable[[int], str])
'typing.Callable[[int], str]'

The variant from collections is wrong, it is not consistent with other 
GenericAlias reprs like
>>> repr(tuple[list[float], int, str])
'tuple[list[float], int, str]'

The problem is actually in the list usage to denote callable arguments:
>>> repr(tuple[[float], int, str])
"tuple[[], int, str]"

Here is the same error. This error disallows to use typing in eval/exec 
statements:
>>> c = collections.abc.Callable[[int], str]
>>> d = eval(repr(c))
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1
collections.abc.Callable[[], str]
  ^
SyntaxError: invalid syntax

Ofc there is no such problem with typing.Callable:
>>> c = typing.Callable[[int], str]
>>> d = eval(repr(c))
>>> 

Interesting, if pass a list into typing.Tuple, an exception is raised:
>>> repr(typing.Tuple[[float], int, str])
Traceback (most recent call last):
  File "", line 1, in 
  File "f:\software\python3.9\lib\typing.py", line 262, in inner
return func(*args, **kwds)
  File "f:\software\python3.9\lib\typing.py", line 896, in __getitem__
params = tuple(_type_check(p, msg) for p in params)
  File "f:\software\python3.9\lib\typing.py", line 896, in 
params = tuple(_type_check(p, msg) for p in params)
  File "f:\software\python3.9\lib\typing.py", line 151, in _type_check
raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Tuple[t0, t1, ...]: each t must be a type. Got [].

I think it is not correct that tuple accepts lists as generics, i. e. for 
tuple[[float], int, str] an exception as above should be raised. Bu this is the 
topic for other issue (maybe even already reported).

--
messages: 384068
nosy: Prometheus3375
priority: normal
severity: normal
status: open
title: Different repr for collections.abc.Callable and typing.Callable
type: behavior
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com