pytypes
pytypes copied to clipboard
get_Generic_parameters should return Any if no parmeters
If I understand correctly, the following class Bar
has all parameters set to Any
:
from typing import *
A = TypeVar('A')
class Foo(Generic[A]):
pass
class Bar(Foo):
pass
But pytypes.type_util.get_Generic_parameters(Bar, Foo)
fails with:
TypeError: Bar has no proper parameters defined by Foo.
But it should return:
(typing.Any,)
From documentation:
Using a generic class without specifying type parameters assumes
Any
for each position. In the following example,MyIterable
is not generic but implicitly inherits fromIterable[Any]
:
from typing import Iterable
class MyIterable(Iterable): # Same as Iterable[Any]
This might be a bug. However I'm not sure if it should just return Any
in that case, because it searches for parameters for Bar
if seen as Foo
. However, in a more general case there might be actual parameters from a parent of Foo
that should not be obtained by a call using Foo
. Returning Any
in that case would be misleading.
Hm, what I am trying to say is that based on documentation:
class Bar(Foo):
pass
is equivalent to:
class Bar(Foo[Any]):
pass
So I would guess that calling get_Generic_parameters
should return Any
. But maybe I am misunderstanding your comment/point.