Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Acquisition
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
Acquisition
Commits
5ca78ace
Commit
5ca78ace
authored
Mar 29, 2015
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test for a static Base mixin; this one runs under Python3
parent
82101534
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
7 deletions
+52
-7
src/Acquisition/__init__.py
src/Acquisition/__init__.py
+3
-2
src/Acquisition/tests.py
src/Acquisition/tests.py
+49
-5
No files found.
src/Acquisition/__init__.py
View file @
5ca78ace
...
...
@@ -29,8 +29,9 @@ def _has__of__(obj):
"""Check whether an object has an __of__ method for returning itself
in the context of a container."""
# It is necessary to check both the type (or we get into cycles)
# as well as the presence of the method (or mixins of Base
# post-class-creation as done somewhere in Zope) can fail.
# as well as the presence of the method (or mixins of Base pre- or
# post-class-creation as done in, e.g.,
# zopefoundation/Persistence) can fail.
return
isinstance
(
obj
,
ExtensionClass
.
Base
)
and
hasattr
(
type
(
obj
),
'__of__'
)
...
...
src/Acquisition/tests.py
View file @
5ca78ace
...
...
@@ -1775,8 +1775,8 @@ if PY2:
def
test_mixin_post_class_definition
():
"""
Code in Zope mixes in ExtensionClass.Base to existing
classes after they've been defined
.
Mixing in Base after class definition doesn't break anything,
but also doesn't result in any wrappers
.
>>> from ExtensionClass import Base
>>> class Plain(object):
...
...
@@ -1787,7 +1787,7 @@ if PY2:
>>> isinstance(Plain(), Base)
True
Even after
they do this
, when we request such an object
Even after
mixing in that base
, when we request such an object
from an implicit acquiring base, it doesn't come out wrapped:
>>> from Acquisition import Implicit
...
...
@@ -1800,14 +1800,58 @@ if PY2:
True
This is because after the mixin, even though Plain is-a Base,
it doesn't provide the `__of__` method used for wrapping
(that only gets added at class definition time, or in C code):
it's still not an Explicit/Implicit acquirer and provides
neither the `__of__` nor `__get__` methods necessary
(`__get__` is added as a consequence of `__of__` at class creation time):
>>> hasattr(Plain, '__get__')
False
>>> hasattr(Plain, '__of__')
False
"""
def
test_mixin_base
():
"""
We can mix-in Base as part of multiple inheritance.
>>> from ExtensionClass import Base
>>> class MyBase(object):
... pass
>>> class MixedIn(Base,MyBase):
... pass
>>> MixedIn.__bases__ == (Base,MyBase)
True
>>> isinstance(MixedIn(), Base)
True
Because it's not an acquiring object and doesn't provide `__of__`
or `__get__`, when accessed from implicit contexts it doesn't come
out wrapped:
>>> from Acquisition import Implicit
>>> class I(Implicit):
... pass
>>> root = I()
>>> root.a = I()
>>> root.a.b = MixedIn()
>>> type(root.a.b) is MixedIn
True
This is because after the mixin, even though Plain is-a Base,
it doesn't provide the `__of__` method used for wrapping, and so
the class definition code that would add the `__get__` method also
doesn't run:
>>> hasattr(MixedIn, '__of__')
False
>>> hasattr(MixedIn, '__get__')
False
"""
def
show
(
x
):
print
(
showaq
(
x
).
strip
())
...
...
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