classification
Title: functools.partial is weak referncable
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: asvetlov, docs@python, mdk, serhiy.storchaka, xtreak
Priority: normal Keywords:

Created on 2018-09-28 09:20 by mdk, last changed 2018-09-28 09:50 by serhiy.storchaka. This issue is now closed.

Messages (5)
msg326617 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2018-09-28 09:20
According to the doc:

    :class:`partial` objects are like :class:`function` objects in that they are callable, weak referencable, and can have attributes.

I don't understand why "weak" here, and it's the only occurence of "weak referencable" in the documentation.

I don't see an object in Python being referencable but NOT weak referencable, do I miss something obvious here?
msg326619 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2018-09-28 09:36
```

In [1]: import weakref                                                                                                    

In [2]: class A: 
   ...:     __slots__ = ()                                                                                                

In [3]: weakref.ref(A())                                                                                                  
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-60f73a442704> in <module>
----> 1 weakref.ref(A())

TypeError: cannot create weak reference to 'A' object

```
msg326621 - (view) Author: Julien Palard (mdk) * (Python committer) Date: 2018-09-28 09:42
TIL.

So it really make sense in this context to tell a functools.partial is weak referencable?
msg326622 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2018-09-28 09:43
I think yes.
msg326623 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-28 09:50
Instances of many builtin types are not weak referencable.

>>> weakref.ref(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create weak reference to 'int' object
>>> weakref.ref([])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create weak reference to 'list' object
History
Date User Action Args
2018-09-28 09:50:15serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg326623
2018-09-28 09:43:58mdksetstatus: open -> closed
resolution: not a bug
stage: resolved
2018-09-28 09:43:14asvetlovsetmessages: + msg326622
2018-09-28 09:42:26mdksetmessages: + msg326621
2018-09-28 09:41:07xtreaksetnosy: + xtreak
2018-09-28 09:36:27asvetlovsetnosy: + asvetlov
messages: + msg326619
2018-09-28 09:20:44mdkcreate