[issue38756] Add generic versions of weakref types to typing module

2019-11-10 Thread Guido van Rossum


Guido van Rossum  added the comment:

PEP 585 says

Discussions-To: Typing-Sig 

So I'd start there.

(But honestly I think what Ivan meant is that it would automatically work. Read 
the PEP carefully before posting if you disagree.)

--

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-10 Thread Nils Kattenbeck


Nils Kattenbeck  added the comment:

Okay, if I want to start a discussion about adding weakref types to PEP 585 
where should do it? The mailing list or as an issue in the PEP repo?

--

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-10 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

We already have https://github.com/python/typing/issues/508 for "smart" 
`get_type_hints()` that would use LBYL. Also we had a similar discussion about 
PathLike, and ultimately decided not to make `typing` a place for generic 
versions of everything.

Finally, in view of PEP 585 some of these things may actually become 
subscriptable at runtime. So I propose to just close this issue.

--
resolution:  -> wont fix
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



[issue38756] Add generic versions of weakref types to typing module

2019-11-10 Thread Guido van Rossum

Guido van Rossum  added the comment:

@ilevkivskyi Is this important enough to change get_type_hints()?

Otherwise let’s close this issue.

--

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-10 Thread Nils Kattenbeck


Nils Kattenbeck  added the comment:

Okay nevermind, after looking in the PEP again and inspecting the 
__annotations__ property I learned that annotations are never evaluated and 
just saved as a string when using said future statement.

However this may still be relevant as typing.get_type_hints will still fail. 
For my use case however this is sufficient.

--

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-10 Thread Nils Kattenbeck


Nils Kattenbeck  added the comment:

Yes thank you, using 'from __future__ import annotations' works fantastic.

I did not knew about this functionality of the annotations future import 
statement, I thought it was only for postponed evaluation but I probably missed 
something in the PEP...

--

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-09 Thread Guido van Rossum


Guido van Rossum  added the comment:

Well, in typeshed, weakref.WeakSet and the others are generic, so you should be 
able to write

  from __future__ import annotations

  from weakref import WeakSet

  users: WeakSet[User]

Or if you need to support Python versions < 3.7, you could write

  users: 'WeakSet[User]'

Does that not solve your problem? It would be easier than adding yet another 
random class (or classes) to typing, which won't work for Python < 3.9 because 
typing.py is in the stdlib (and PEP 484 is no longer provisional).

--

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-09 Thread Nils Kattenbeck


Nils Kattenbeck  added the comment:

A possible use case would be having multiple users and some groups said users 
can belong to. When using a WeakSet a user won't be part of a groups after he 
deleted his account without having to iterate over all groups.

class User: pass

class Group:
  users: WeakSet[User]

  def __init__(self, users: Iterable[User]):
self.users = WeakSet(users)

# somewhere else a collection of all active users


Types I would like to see added as a generic would be primarily:
- WeakKeyDictionary
- WeakValueDictionary
- WeakSet

Additionally it would be nice to have generic versions of:
- ref (would probably return Optional[T] on call?)
- WeakMethod
- ProxyType
- CallableProxyType

Although the last two could probably be just annotated using T because they 
mostly should behave the same...

--

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-09 Thread Guido van Rossum


Guido van Rossum  added the comment:

OK, can you give some example use cases? Can you provide a list of types that 
you want to see added?

--

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-09 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +gvanrossum, levkivskyi

___
Python tracker 

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



[issue38756] Add generic versions of weakref types to typing module

2019-11-09 Thread Nils Kattenbeck


New submission from Nils Kattenbeck :

I would like to request the addition of generic variants of some of the types 
in weakref to the typing module.
This would for example include weakref.WeakKeyDictionary among others.

Doing so would allow one to add type annotations to code using such data 
structures.

--
components: Library (Lib)
messages: 356304
nosy: Nils Kattenbeck
priority: normal
severity: normal
status: open
title: Add generic versions of weakref types to typing module
type: enhancement
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