[issue32162] typing.Generic breaks __init_subclass__

2018-04-02 Thread Will T

Will T  added the comment:

Done: https://bugs.python.org/issue33207 - thanks for the quick response!

--

___
Python tracker 

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



[issue32162] typing.Generic breaks __init_subclass__

2018-04-02 Thread Ivan Levkivskyi

Ivan Levkivskyi  added the comment:

Thanks Will!

I think this is actually a different (although very similar issue). It looks 
like it is easy to fix. Could you please open a separate issue (and mention it 
here)? Also could you please provide a typical example when this breaks so that 
I can add an appropriate test with the fix?

--

___
Python tracker 

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



[issue32162] typing.Generic breaks __init_subclass__

2018-04-02 Thread Will T

Will T  added the comment:

I believe I'm experiencing a related bug in the new (3.7) version 
unfortunately. The current version of typing.Generic.__init_subclass__ isn't 
chaining to super(Generic, cls).__init_subclass__, meaning Generic's position 
in class bases can prevent subsequent bases from working properly. I can 
currently work around it with this unsightly hack but it's obviously suboptimal:

_old_generic_init_subclass = object.__getattribute__(ta.Generic, 
'__init_subclass__').__func__
@classmethod  # noqa
def _new_generic_init_subclass(cls, *args, **kwargs):  # noqa
_old_generic_init_subclass(cls, *args, **kwargs)
super(ta.Generic, cls).__init_subclass__(*args, **kwargs)
ta.Generic.__init_subclass__ = _new_generic_init_subclass  # noqa

--
nosy: +wrmsr

___
Python tracker 

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



[issue32162] typing.Generic breaks __init_subclass__

2018-02-18 Thread Ivan Levkivskyi

Ivan Levkivskyi  added the comment:

FWIW, this is fixed in 3.7 by PEP 560, providing a separate fix for 3.6 is not 
easy, and you have a good workaround, so I propose to close this issue.

--
resolution:  -> fixed
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



[issue32162] typing.Generic breaks __init_subclass__

2017-12-01 Thread Ivan Levkivskyi

Change by Ivan Levkivskyi :


--
nosy: +levkivskyi

___
Python tracker 

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



[issue32162] typing.Generic breaks __init_subclass__

2017-11-28 Thread Ilya Kulakov

Ilya Kulakov  added the comment:

That's a better workaround:

class X(typing.Generic[T]):
def __init_subclass__(cls, **kwargs):
super(typing.GenericMeta, cls).__setattr__('_gorg', cls)
super().__init_subclass__(**kwargs)

--

___
Python tracker 

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



[issue32162] typing.Generic breaks __init_subclass__

2017-11-28 Thread Ilya Kulakov

Ilya Kulakov  added the comment:

Nah, that's a bad one: you cannot use Generic classes as intended by specifying 
types.

It looks like it happens because cls._grog is not yet set properly by the time 
__init_subclass__ is called.

--

___
Python tracker 

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



[issue32162] typing.Generic breaks __init_subclass__

2017-11-28 Thread Ilya Kulakov

Ilya Kulakov  added the comment:

Current workaround is

class X(typing.Generic[T] if typing.TYPE_CHECKING else object):

--

___
Python tracker 

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



[issue32162] typing.Generic breaks __init_subclass__

2017-11-28 Thread Ilya Kulakov

Ilya Kulakov  added the comment:

This issue is more server that I expected: it doesn't just propagate value to 
superclasses, but overrides them. The last subclass created by Python runtime 
will overwrite value for the whole chain.

--

___
Python tracker 

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



[issue32162] typing.Generic breaks __init_subclass__

2017-11-28 Thread Ilya Kulakov

New submission from Ilya Kulakov :

When superclass inherits from Generic, attributes set for a subclass are 
incorrectly propagated to its superclass.

Without Generic attribute access raises an exception:

class X:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
cls.attr = 42

class Y(X):
pass

Y.attr  # 42
X.attr  # AttributeError

With Generic it does not:

import typing

T = typing.TypeVar('T')

class X(typing.Generic[T]):
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
cls.attr = 42

class Y(X):
pass

Y.attr  # 42
X.attr  # 42

--
messages: 307182
nosy: Ilya.Kulakov
priority: normal
severity: normal
status: open
title: typing.Generic breaks __init_subclass__
type: behavior
versions: Python 3.6

___
Python tracker 

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