pytypes icon indicating copy to clipboard operation
pytypes copied to clipboard

get_Generic_parameters should return Any if no parmeters

Open mitar opened this issue 6 years ago • 2 comments

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 from Iterable[Any]:

from typing import Iterable

class MyIterable(Iterable): # Same as Iterable[Any]

mitar avatar Dec 13 '17 12:12 mitar

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.

Stewori avatar Dec 13 '17 16:12 Stewori

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.

mitar avatar Dec 13 '17 19:12 mitar