[issue36009] weakref.ReferenceType is not a valid typing type

2019-02-16 Thread Alexander Mohr


Alexander Mohr  added the comment:

doing the __future__ doesn't help anything as it is an invalid type

--

___
Python tracker 

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



[issue36009] weakref.ReferenceType is not a valid typing type

2019-02-16 Thread Ivan Levkivskyi


Ivan Levkivskyi  added the comment:

This question appeared several times before, and the conclusion is that we are 
not going to do this.

There are many cases in standard library that are generic in stubs (and by 
nature) but are not declared as such at runtime, so we simply can't provide a 
typing equivalent for all of them.

In Python 3.7 you can just use from __future__ import annotations for those, 
and/or use the recipes described here 
https://mypy.readthedocs.io/en/latest/common_issues.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime

Maybe at some point we will start using `Generic` in standard library, but for 
now I am closing this as wontfix.

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



[issue36009] weakref.ReferenceType is not a valid typing type

2019-02-16 Thread Alexander Mohr


Alexander Mohr  added the comment:

I'm not a typing expert, but from what I understand you could do:

  class Bar: pass

  foo: Callable[[], Bar] = weakref.ref(Bar())

but you lose the typing weakref.ref.

OTOH if you simply do:

  foo: weakref.ref = weakref.ref(Bar())

you lose the info of Bar ;)

--

___
Python tracker 

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



[issue36009] weakref.ReferenceType is not a valid typing type

2019-02-16 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



[issue36009] weakref.ReferenceType is not a valid typing type

2019-02-16 Thread Alexander Mohr


New submission from Alexander Mohr :

For valid types which encapsulate other types, like typing.List or 
typing.Tuple, you can declare what's contained in them like so:

foo: typing.List[int] = []

Unfortunately weakref.ReferenceType does not allow you to do this.  You get the 
error:
>>> foo: weakref.ReferenceType[typing.Any] = None
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'type' object is not subscriptable

so either ReferenceType should be fixed or a new type made available.

--
components: Library (Lib)
messages: 335674
nosy: thehesiod
priority: normal
severity: normal
status: open
title: weakref.ReferenceType is not a valid typing type
type: behavior
versions: Python 3.6, Python 3.7

___
Python tracker 

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