[issue38298] Base class of generic type has wrong `cls` argument in classmethods

2019-09-28 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

Yes, it is unfortunately hard to support with the new design. Also note that 
this was previously discussed at https://github.com/python/typing/issues/629. I 
think we can close this, since the other issue has more context.

--
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



[issue38298] Base class of generic type has wrong `cls` argument in classmethods

2019-09-27 Thread Guido van Rossum


Guido van Rossum  added the comment:

For performance reasons the implementation of generics changed completely in 
3.7. I don't think we can restore the behavior you observed in 3.6.

--

___
Python tracker 

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



[issue38298] Base class of generic type has wrong `cls` argument in classmethods

2019-09-27 Thread Ned Deily


Change by Ned Deily :


--
nosy: +gvanrossum, levkivskyi

___
Python tracker 

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



[issue38298] Base class of generic type has wrong `cls` argument in classmethods

2019-09-27 Thread Kefei Lu


New submission from Kefei Lu :

This is a new regression in Python3.7.


Create the following file as `test.py`

```
# test.py

import typing as t


T = t.TypeVar("T")


class BaseOfGeneric:

@classmethod
def f(cls):
# when called from an instantiated generic type, e.g.,
# `MyList[int]`, expect `cls` to be the GenericAlias with its type
# argument already insteantiated
print(f"current class is {cls}")
print(f"current class's type: {type(cls)}")


class MyList(t.List[T], BaseOfGeneric):
pass


MyIntList = MyList[int]

MyIntList.f()
```

Run with Python3.6:

>>> python3.6 ./test.py 
current class is __main__.MyList[int]
 ^^^ as expected

current class's type: 

EXPECTED BEHAVIOR: The outcome is expected: `cls` of `BaseOfGeneric.f` should 
be `MyList` **with** type argument `int`


However this is wrong in Python3.7:

>>> python3.7 ./test.py 
current class is 
 ^^^ type argument is LOST !!!

current class's type: 

Note that `cls` of `BaseOfGeneric.f` has lost the type argument `int`! It is 
not expected.

--
messages: 353386
nosy: kflu
priority: normal
severity: normal
status: open
title: Base class of generic type has wrong `cls` argument in classmethods
type: behavior
versions: Python 3.7

___
Python tracker 

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