[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-07 Thread Batuhan


Batuhan  added the comment:

> I think that applying the same to PathLike makes sense as well, but it 
> deserves another issue.

Yes, it looks like they are using that in typeshed. I'm opening another issue 
with a patch. Thanks for reminding that

--

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-07 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

Done.
I think that applying the same to PathLike makes sense as well, but it deserves 
another issue.

--

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-07 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

Thanks, Batuhan!

--

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-07 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
resolution:  -> fixed
stage: patch review -> 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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-07 Thread miss-islington

miss-islington  added the comment:


New changeset dec367261e7e2bb4dd42feeb58031abed2ade683 by Miss Islington (bot) 
(Batuhan Taşkaya) in branch 'master':
bpo-38978: Implement __class_getitem__ for asyncio objects (GH-17491)
https://github.com/python/cpython/commit/dec367261e7e2bb4dd42feeb58031abed2ade683


--
nosy: +miss-islington

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-07 Thread Batuhan


Change by Batuhan :


--
keywords: +patch
pull_requests: +16969
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/17491

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-05 Thread Guido van Rossum


Guido van Rossum  added the comment:

I'm actually missing context, so I will leave this up to you all.

--

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-05 Thread Batuhan


Batuhan  added the comment:

I want to be a volunteer, if no one is working on this.

--
nosy: +BTaskaya

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-05 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

I see the point in using ``__class_getitem__`` in Python classes too, we can 
probably start using a dummy method returning class object itself now. Also PEP 
585 already has a long list of candidates for "proper" ``__class_getitem__`` 
support. Maybe we can add these classes to that list? Maybe it would make sense 
to also have ``PathLike`` there?

--
nosy: +lukasz.langa

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-05 Thread Guido van Rossum


Guido van Rossum  added the comment:

Well, __class_getitem__ was added primarily to allow classes implemented in
*C* to support "generics". This is helpful to support PEP 585. For classes
written in Python I don't see the point.

But I'll leave the rest of this to Ivan.

--

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-05 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

I thought __class_getitem__ was invented exactly to simplify generic types 
support.

The only thing that confuses me an example from PEP 560:

class MyList:
def __getitem__(self, index):
return index + 1
def __class_getitem__(cls, item):
return f"{cls.__name__}[{item.__name__}]"

It prevents from instantiating a generic on inheritance, e.g. the following 
code raises TypeError:

class MyOtherList(MyList[int]):
pass

It would be nice if Ivan clarifies what is the best practice in this case.
I think the method should return unmodified class, not a string.

--

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-05 Thread Guido van Rossum


Guido van Rossum  added the comment:

In principle I think this is a good idea.

If this was user code, we would inherit from typing.Generic. I understand you 
wanting to avoid the overhead of that. But will it work correctly at runtime 
with other typing constructors? I guess __annotations__ will not show the 
generic type's parameter. Will anybody care?

Maybe we need to walk through some detailed examples.

--

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-05 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
nosy: +gvanrossum, levkivskyi

___
Python tracker 

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



[issue38978] Implement __class_getitem__ for Future, Task, Queue

2019-12-05 Thread Andrew Svetlov


New submission from Andrew Svetlov :

Typeshed declares asyncio.Future, asyncio.Task and asyncio.Queue as generic 
types, which is 100% correct.

The problem is that these classes don't support generic instantiation in 
runtime, e.g. Future[str] raises TypeError.

The feature should be implemented by adding __class_getitem__ methods which 
return self.

The patch is trivial but requires a few lines of C code for C Accelerated CTask 
and CFuture as well as updating Python code.

A volunteer is welcome!

--
components: asyncio
keywords: easy, easy (C)
messages: 357848
nosy: asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Implement __class_getitem__ for Future, Task, Queue
versions: Python 3.9

___
Python tracker 

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