Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
eacc7441
Commit
eacc7441
authored
Aug 06, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't double-descriptor @staticmethod objects. Fixes #1266
parent
d0aa959f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
6 deletions
+42
-6
CHANGES.rst
CHANGES.rst
+4
-0
src/gevent/local.py
src/gevent/local.py
+16
-6
src/greentest/test__local.py
src/greentest/test__local.py
+22
-0
No files found.
CHANGES.rst
View file @
eacc7441
...
...
@@ -12,6 +12,10 @@
3.7 or they will crash. Reported by Alexey Stepanov in :issue:`1260`
and pkittenis in :issue:`1261`.
- :class:`gevent.local.local` subclasses correctly supports
``@staticmethod`` functions. Reported by Brendan Powers in
:issue:`1266`.
1.3.5 (2018-07-16)
==================
...
...
src/gevent/local.py
View file @
eacc7441
...
...
@@ -438,13 +438,23 @@ class local(object):
return
dct
[
name
]
if
name
in
self
.
_local_type_vars
:
type_attr
=
getattr
(
self
.
_local_type
,
name
)
# It's not in the dict at all. Is it in the type?
# Not in the dictionary, but is found in the type. It could be
# a non-data descriptor still. Some descriptors, like @staticmethod,
# return objects (functions, in this case), that are *themselves*
# descriptors, which when invoked, again, would do the wrong thing.
# So we can't rely on getattr() on the type for them, we have to
# look through the MRO dicts ourself.
if
name
not
in
self
.
_local_type_get_descriptors
:
# Not a descriptor, can't execute code
return
type_attr
return
type
(
type_attr
).
__get__
(
type_attr
,
self
,
self
.
_local_type
)
# Not a descriptor, can't execute code. So all we need is
# the return value of getattr() on our type.
return
getattr
(
self
.
_local_type
,
name
)
for
base
in
self
.
_local_type
.
mro
():
bd
=
base
.
__dict__
if
name
in
bd
:
attr_on_type
=
bd
[
name
]
result
=
type
(
attr_on_type
).
__get__
(
attr_on_type
,
self
,
self
.
_local_type
)
return
result
# It wasn't in the dict and it wasn't in the type.
# So the next step is to invoke type(self)__getattr__, if it
...
...
src/greentest/test__local.py
View file @
eacc7441
...
...
@@ -83,6 +83,20 @@ class LocalWithABC(local, Mapping):
def
__len__
(
self
):
return
len
(
self
.
d
)
class
LocalWithStaticMethod
(
local
):
@
staticmethod
def
a_staticmethod
():
return
42
class
LocalWithClassMethod
(
local
):
@
classmethod
def
a_classmethod
(
cls
):
return
cls
class
TestGeventLocal
(
greentest
.
TestCase
):
# pylint:disable=attribute-defined-outside-init,blacklisted-name
...
...
@@ -352,6 +366,14 @@ class TestGeventLocal(greentest.TestCase):
self
.
assertIn
(
'a'
,
x
.
d
)
self
.
assertEqual
([
'a'
],
list
(
x
.
keys
()))
def
test_local_with_staticmethod
(
self
):
x
=
LocalWithStaticMethod
()
self
.
assertEqual
(
42
,
x
.
a_staticmethod
())
def
test_local_with_classmethod
(
self
):
x
=
LocalWithClassMethod
()
self
.
assertIs
(
LocalWithClassMethod
,
x
.
a_classmethod
())
try
:
from
zope
import
interface
except
ImportError
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment