classification
Title: Documented caching for shared library's __getattr__ and __getitem__ is incorrect
Type: behavior Stage: resolved
Components: ctypes, Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: amaury.forgeotdarc, belopolsky, docs@python, eric.araujo, erijo, loewis, meador.inge, python-dev, r.david.murray, theller
Priority: normal Keywords: easy, patch

Created on 2012-03-05 14:23 by erijo, last changed 2014-10-04 22:27 by r.david.murray. This issue is now closed.

Files
File name Uploaded Description Edit
issue14201.patch erijo, 2012-07-16 19:13 Patch to documentation review
issue14201-v2.patch meador.inge, 2012-07-20 03:42
Messages (12)
msg154949 - (view) Author: Erik Johansson (erijo) Date: 2012-03-05 14:23
I would expect that the following code would give True as result:

>>> from ctypes import *
>>> libc = CDLL("libc.so.6")
>>> libc.time == libc['time']
False

Is it by design that libc['time'] always returns a different _FuncPtr object? It is a bit confusing when doing things like:

libc['time'].restype = ...
libc['time'].argtypes = [...]

# python --version
Python 2.7.2+

Ubunutu version 2.7.2-5ubuntu1.
msg154957 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-03-05 16:13
This is intentional; the caching was removed in 214b28d7a999. Thomas, can you remember the rationale for this change?
msg155089 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2012-03-07 14:02
The rationale was to allow different packages (for example) in the same process to have their own private instance of a foreign function, with possibly different definitions of restype, argtypes and/or errcheck.
msg155091 - (view) Author: Erik Johansson (erijo) Date: 2012-03-07 14:56
Perhaps this behaviour should be documented somewhere (unless it already is)?
msg155092 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-03-07 15:08
Item access is documented in this section: http://docs.python.org/library/ctypes#loading-shared-libraries (scroll a bit down looking for __getitem__); the wording about caching is ambiguous with respect to the current behavior.
msg155094 - (view) Author: Erik Johansson (erijo) Date: 2012-03-07 15:34
Ah, I see. I modified the title to reflect this.

Perhaps adding this simple example as well can help people (e.g. me) see it?

>>> libc.time == libc.time
True
>>> libc['time'] == libc['time']
False
msg165646 - (view) Author: Erik Johansson (erijo) Date: 2012-07-16 19:13
Document the difference between __getattr__ and __getitem__.
msg165898 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-07-20 03:42
The general wording and example look good;  thanks.  I reworded things a little.  Updated patch attached.
msg166455 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-07-26 04:02
Any comments on this one?  I plan on committing the changes tomorrow unless I hear something otherwise.
msg171302 - (view) Author: Erik Johansson (erijo) Date: 2012-09-25 18:03
The issue14201-v2.patch patch looks good to me at least.
msg228505 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-04 22:26
New changeset ae64614b66b7 by R David Murray in branch '2.7':
#14201: Update ctypes docs to match behavior changed from 214b28d7a999.
https://hg.python.org/cpython/rev/ae64614b66b7

New changeset 5518aa0fbc06 by R David Murray in branch '3.4':
#14201: Update ctypes docs to match behavior changed from 214b28d7a999.
https://hg.python.org/cpython/rev/5518aa0fbc06

New changeset dfdcc3fad3aa by R David Murray in branch 'default':
Merge: #14201: Update ctypes docs to match behavior changed from 214b28d7a999.
https://hg.python.org/cpython/rev/dfdcc3fad3aa
msg228507 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-04 22:27
Committed.  See also issue 22552.
History
Date User Action Args
2014-10-04 22:27:59r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg228507

resolution: fixed
stage: commit review -> resolved
2014-10-04 22:26:51python-devsetnosy: + python-dev
messages: + msg228505
2012-09-25 18:03:15erijosetmessages: + msg171302
2012-07-26 04:02:02meador.ingesetmessages: + msg166455
2012-07-20 03:42:11meador.ingesetfiles: + issue14201-v2.patch

messages: + msg165898
stage: needs patch -> commit review
2012-07-16 19:13:33erijosetfiles: + issue14201.patch
keywords: + patch
messages: + msg165646
2012-03-07 15:34:01erijosetmessages: + msg155094
title: libc.time != libc['time'] -> Documented caching for shared library's __getattr__ and __getitem__ is incorrect
2012-03-07 15:08:30eric.araujosetassignee: docs@python
components: + Documentation

keywords: + easy
nosy: + docs@python, eric.araujo
messages: + msg155092
stage: needs patch
2012-03-07 14:56:40erijosetmessages: + msg155091
2012-03-07 14:02:17thellersetmessages: + msg155089
2012-03-05 16:13:24loewissetnosy: + theller, loewis
messages: + msg154957
2012-03-05 15:11:49pitrousetnosy: + amaury.forgeotdarc, belopolsky, meador.inge

versions: + Python 3.2, Python 3.3
2012-03-05 14:23:40erijocreate