This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: typing module conflicts with __slots__-classes
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: grayfall, levkivskyi
Priority: normal Keywords:

Created on 2017-08-24 18:34 by grayfall, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg300797 - (view) Author: Ilia Korvigo (grayfall) Date: 2017-08-24 18:34
I've got conflicts between Python's typing system and `__slots__`. Here is a small reproducible example.

    from typing import TypeVar, Generic, Sequence
    
    T = TypeVar("T")

    class TestGeneric(Sequence, Generic[T]):
        __slots__ = ("test",)

        def __init__(self, test: T):
            self.test = [test]
        
        def __iter__(self):
            return iter(self.test)
        def __len__(self):
            return len(self.test)
        
        def __contains__(self, item):
            return item in self.test
        
        def __getitem__(self, _):
            return self.test[0]

Now whenever I try to specify a content type, e.g.
    
    V = TestGeneric[int]

I get 

    ValueError: 'test' in __slots__ conflicts with class variable

I use `Generics`  in classes without slots a lot, hence I think this error has to be linked to `__slots__`. Moreover, the same class works fine, if you remove the `__slots__`
msg300854 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2017-08-25 18:43
I think this is fixed in latest version. I thought it was also backported to Python 3.5.3. What is the version you are using? Could you please try updating to the latest bugfix release? (currently these are 3.5.4 and 3.6.2).
msg300946 - (view) Author: Ilia Korvigo (grayfall) Date: 2017-08-28 09:38
Indeed, this issue has been fixed. Anyway, it is not mentioned in any release notes. Perhaps, this should be mentioned somewhere. 

> On 25 Aug 2017, at 21:43, Ivan Levkivskyi <report@bugs.python.org> wrote:
> 
> 
> Ivan Levkivskyi added the comment:
> 
> I think this is fixed in latest version. I thought it was also backported to Python 3.5.3. What is the version you are using? Could you please try updating to the latest bugfix release? (currently these are 3.5.4 and 3.6.2).
> 
> ----------
> nosy: +levkivskyi
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue31272>
> _______________________________________
msg300949 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2017-08-28 10:41
It is listed in Misc/NEWS as "minor bug fixes" in typing module, I don't think this is something that deserves a separate line in release notes.
History
Date User Action Args
2022-04-11 14:58:51adminsetgithub: 75455
2017-08-28 10:41:52levkivskyisetstatus: open -> closed
resolution: out of date
messages: + msg300949

stage: resolved
2017-08-28 09:38:40grayfallsetmessages: + msg300946
2017-08-25 18:43:36levkivskyisetnosy: + levkivskyi
messages: + msg300854
2017-08-24 18:34:24grayfallcreate