This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: _threading_local.py logic error in _localbase __new__
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: amaury.forgeotdarc Nosy List: ajaksu2, akuchling, amaury.forgeotdarc, gvanrossum, jackdied, tony_nelson
Priority: normal Keywords: needs review, patch

Created on 2006-07-14 00:52 by tony_nelson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
localbase.patch amaury.forgeotdarc, 2009-03-30 13:20
Messages (7)
msg60941 - (view) Author: Tony Nelson (tony_nelson) Date: 2006-07-14 00:52
I don't understand _threading_local.py, but I think
that parens are needed below in class _localbase __new__().

    if args or kw and (cls.__init__ is object.__init__):
        raise TypeError...

should be "(args or kw)", I think, looking at the
related test in _patch().

I'm not quite sure if this is python 2.5, but it is in
trunk.
msg84507 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-30 05:07
It isn't obvious to me that this issue is valid.

Some more context:

class _localbase(object):
    __slots__ = '_local__key', '_local__args', '_local__lock'

    def __new__(cls, *args, **kw):
        self = object.__new__(cls)
        key = '_local__key', 'thread.local.' + str(id(self))
        object.__setattr__(self, '_local__key', key)
        object.__setattr__(self, '_local__args', (args, kw))
        object.__setattr__(self, '_local__lock', RLock())

        if args or kw and (cls.__init__ is object.__init__):
            raise TypeError("Initialization arguments are not supported")
msg84543 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-03-30 13:20
It is still valid:

>>> class MyLocal(local):
...    def __init__(self, *args, **kwargs):
...        self.args = args
...        self.kwargs = kwargs
...
>>> MyLocal(1)

This works when local is thread._local (from thread import _local as
local), but fails when imported from _threading_local (from
_threading_local import local)

See attached patch for the test case (and the fix of course)
msg84566 - (view) Author: Tony Nelson (tony_nelson) Date: 2009-03-30 15:40
Thanks, Amaury.  The new test works here on Python2.6.1, failing without
the fix and passing with it.  (Passing MyLocal(a=1) and failing
MyLocal(1), as expected.)  With the fix, _threading_local.py supports
positional arguments to subclass __init__, as well as keyword arguments.
msg84571 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2009-03-30 16:04
Looks good to me. Amaury, can you make sure this lands in 2.6, 2.7, 3.0
and 3.1?
msg99810 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2010-02-22 18:49
This fix still needs to be committed, apparently.
msg99819 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2010-02-22 19:57
committed to 2.x in r78336
committed to 3.x in r78337
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43673
2010-02-22 19:57:17jackdiedsetstatus: open -> closed
nosy: + jackdied
messages: + msg99819

2010-02-22 18:49:09akuchlingsetnosy: + akuchling
messages: + msg99810
2009-03-30 16:04:08gvanrossumsetnosy: + gvanrossum
messages: + msg84571

assignee: amaury.forgeotdarc
resolution: accepted
2009-03-30 15:40:36tony_nelsonsetmessages: + msg84566
2009-03-30 13:20:10amaury.forgeotdarcsetfiles: + localbase.patch

nosy: + amaury.forgeotdarc
messages: + msg84543

keywords: + needs review, patch
2009-03-30 05:07:44ajaksu2setversions: + Python 2.6, - Python 2.5
nosy: + ajaksu2

messages: + msg84507

type: behavior
stage: test needed
2006-07-14 00:52:48tony_nelsoncreate