[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

[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

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

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

[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

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

[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

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

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

[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

[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