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
0ac8c76b
Commit
0ac8c76b
authored
May 07, 2018
by
Jason Madden
Committed by
GitHub
May 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1203 from gevent/issue1201
Fix ABCs in the MRO of gevent.local. Fixes #1201
parents
1e4e22d8
eb9cc5be
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
3 deletions
+34
-3
CHANGES.rst
CHANGES.rst
+3
-0
src/gevent/_local.pxd
src/gevent/_local.pxd
+1
-1
src/gevent/local.py
src/gevent/local.py
+3
-2
src/greentest/test__local.py
src/greentest/test__local.py
+27
-0
No files found.
CHANGES.rst
View file @
0ac8c76b
...
...
@@ -12,6 +12,9 @@
- Update autoconf's config.guess and config.sub to the latest versions
for c-ares and libev.
- :class:`gevent.local.local` subclasses that mix-in ABCs can be instantiated.
Reported in :issue:`1201` by Bob Jordan.
1.3b2 (2018-05-03)
==================
...
...
src/gevent/_local.pxd
View file @
0ac8c76b
...
...
@@ -102,7 +102,7 @@ cdef inline dict _local_get_dict(local self)
@
cython
.
locals
(
entry
=
_localimpl_dict_entry
)
cdef
_local__copy_dict_from
(
local
self
,
_localimpl
impl
,
dict
duplicate
)
@
cython
.
locals
(
mro
=
list
,
base
=
type
,
gets
=
set
,
dels
=
set
,
set_or_del
=
set
,
@
cython
.
locals
(
mro
=
list
,
gets
=
set
,
dels
=
set
,
set_or_del
=
set
,
type_self
=
type
,
type_attr
=
type
,
sets
=
set
)
cdef
tuple
_local_find_descriptors
(
local
self
)
...
...
src/gevent/local.py
View file @
0ac8c76b
...
...
@@ -538,8 +538,9 @@ def _local_find_descriptors(self):
# return other class attributes. So we can't use getattr, and instead
# walk up the dicts
for
base
in
mro
:
if
attr_name
in
base
.
__dict__
:
attr
=
base
.
__dict__
[
attr_name
]
bd
=
base
.
__dict__
if
attr_name
in
bd
:
attr
=
bd
[
attr_name
]
break
else
:
raise
AttributeError
(
attr_name
)
...
...
src/greentest/test__local.py
View file @
0ac8c76b
...
...
@@ -7,6 +7,10 @@ from gevent import monkey; monkey.patch_all()
from
threading
import
local
from
threading
import
Thread
try
:
from
collections.abc
import
Mapping
except
ImportError
:
from
collections
import
Mapping
class
ReadProperty
(
object
):
"""A property that can be overridden"""
...
...
@@ -68,6 +72,18 @@ class WithGetattr(local):
return
42
return
super
(
WithGetattr
,
self
).
__getattr__
(
name
)
class
LocalWithABC
(
local
,
Mapping
):
def
__getitem__
(
self
,
name
):
return
self
.
d
[
name
]
def
__iter__
(
self
):
return
iter
(
self
.
d
)
def
__len__
(
self
):
return
len
(
self
.
d
)
class
TestGeventLocal
(
greentest
.
TestCase
):
# pylint:disable=attribute-defined-outside-init,blacklisted-name
...
...
@@ -325,6 +341,17 @@ class TestGeventLocal(greentest.TestCase):
self
.
assertEqual
(
results
,
[((
MyLocal
,
id
(
x
)),
{
'foo'
:
42
})])
def
test_local_with_abc
(
self
):
# an ABC (or generally any non-exact-type) in the MRO doesn't
# break things. See https://github.com/gevent/gevent/issues/1201
x
=
LocalWithABC
()
x
.
d
=
{
'a'
:
1
}
self
.
assertEqual
({
'a'
:
1
},
x
.
d
)
# The ABC part works
self
.
assertIn
(
'a'
,
x
.
d
)
self
.
assertEqual
([
'a'
],
list
(
x
.
keys
()))
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