Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1fb071cc
Commit
1fb071cc
authored
Aug 25, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Checkpoint.
parent
b2173c31
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
369 additions
and
5 deletions
+369
-5
Demo/metaclasses/Meta.py
Demo/metaclasses/Meta.py
+19
-5
Demo/metaclasses/index.html
Demo/metaclasses/index.html
+350
-0
No files found.
Demo/metaclasses/Meta.py
View file @
1fb071cc
...
...
@@ -29,10 +29,10 @@ class MetaHelper:
raw
=
self
.
__formalclass__
.
__getattr__
(
name
)
except
AttributeError
:
try
:
_getattr_
=
self
.
__dict__
[
'_getattr_'
]
ga
=
self
.
__formalclass__
.
__getattr__
(
'__usergetattr__'
)
except
KeyError
:
raise
AttributeError
,
name
return
_getattr_
(
name
)
return
ga
(
self
,
name
)
if
type
(
raw
)
!=
types
.
FunctionType
:
return
raw
return
self
.
__methodwrapper__
(
raw
,
self
)
...
...
@@ -50,8 +50,13 @@ class MetaClass:
__inited
=
0
def
__init__
(
self
,
name
,
bases
,
dict
):
if
dict
.
has_key
(
'__getattr__'
):
raise
TypeError
,
"Can't override __getattr__; use _getattr_"
try
:
ga
=
dict
[
'__getattr__'
]
except
KeyError
:
pass
else
:
dict
[
'__usergetattr__'
]
=
ga
del
dict
[
'__getattr__'
]
self
.
__name__
=
name
self
.
__bases__
=
bases
self
.
__realdict__
=
dict
...
...
@@ -98,7 +103,16 @@ def _test():
x
=
C
()
print
x
x
.
m1
(
12
)
class
D
(
C
):
def
__getattr__
(
self
,
name
):
if
name
[:
2
]
==
'__'
:
raise
AttributeError
,
name
return
"getattr:%s"
%
name
x
=
D
()
print
x
.
foo
print
x
.
_foo
## print x.__foo
## print x.__foo__
if
__name__
==
'__main__'
:
_test
()
...
...
Demo/metaclasses/index.html
0 → 100644
View file @
1fb071cc
This diff is collapsed.
Click to expand it.
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