[issue40408] GenericAlias does not support nested type variables

2020-05-04 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

> But this behavior is not specified and is not covered by tests.

FWIW, to be most close to the static type checkers behavior, both D[int][str] 
and D[int, str] should fail for D = Dict[T, List]. Not important however, since 
this is a really rare corner case I think.

--

___
Python tracker 

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



[issue40408] GenericAlias does not support nested type variables

2020-05-04 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> 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



[issue40408] GenericAlias does not support nested type variables

2020-05-04 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 41a64587a0fd68bcd21ba42999cd3940801dff7c by Serhiy Storchaka in 
branch 'master':
bpo-40408: Fix support of nested type variables in GenericAlias. (GH-19836)
https://github.com/python/cpython/commit/41a64587a0fd68bcd21ba42999cd3940801dff7c


--

___
Python tracker 

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



[issue40408] GenericAlias does not support nested type variables

2020-05-02 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

There is a difference between PR 19836 and the typing module in handling nested 
unsubscribed generic aliases:

>>> from typing import *
>>> T = TypeVar('T')
>>> D1 = Dict[T, List]
>>> D2 = dict[T, List]
>>> D1.__parameters__
(~T,)
>>> D1[int]
typing.Dict[int, typing.List[~T]]
>>> D1[int].__parameters__
(~T,)
>>> D1[int][str]
typing.Dict[int, typing.List[str]]
>>> D1[int, str]
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/serhiy/py/cpython/Lib/typing.py", line 267, in inner
return func(*args, **kwds)
  File "/home/serhiy/py/cpython/Lib/typing.py", line 686, in __getitem__
_check_generic(self, params)
  File "/home/serhiy/py/cpython/Lib/typing.py", line 221, in _check_generic
raise TypeError(f"Too {'many' if alen > elen else 'few'} parameters for 
{cls};"
TypeError: Too many parameters for typing.Dict[~T, typing.List]; actual 2, 
expected 1
>>> D2.__parameters__
(~T, ~T)
>>> D2[int]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: Too few arguments for dict[~T, typing.List]
>>> D2[int, str]
dict[int, typing.List[str]]

But this behavior is not specified and is not covered by tests.

--

___
Python tracker 

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



[issue40408] GenericAlias does not support nested type variables

2020-05-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +19154
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19836

___
Python tracker 

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



[issue40408] GenericAlias does not support nested type variables

2020-04-30 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
assignee:  -> serhiy.storchaka

___
Python tracker 

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



[issue40408] GenericAlias does not support nested type variables

2020-04-28 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Not yet. If you don't prefer to fix it yourself, I'll do it as soon as I have 
time.

--

___
Python tracker 

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



[issue40408] GenericAlias does not support nested type variables

2020-04-27 Thread Guido van Rossum


Guido van Rossum  added the comment:

Good catch. Is there a reasonable fix?

--

___
Python tracker 

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



[issue40408] GenericAlias does not support nested type variables

2020-04-27 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

While trying to replace typing._GenericAlias with GenericAlias I have found 
that the latter does not support nested type variables.

>>> from typing import *
>>> T = TypeVar('T')
>>> X = List[List[T]]
>>> X.__parameters__
(~T,)
>>> X[int]
typing.List[typing.List[int]]
>>> Y = list[list[T]]
>>> Y.__parameters__
()
>>> Y[int]
Traceback (most recent call last):
  File "", line 1, in 
TypeError: There are no type variables left in list[list[~T]]

--
components: Interpreter Core
messages: 367433
nosy: gvanrossum, levkivskyi, serhiy.storchaka
priority: normal
severity: normal
status: open
title: GenericAlias does not support nested type variables
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