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
8c5c3e3b
Commit
8c5c3e3b
authored
Mar 10, 2013
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #17351: Modernize the pure Python property() example.
parent
5f52246f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
Doc/howto/descriptor.rst
Doc/howto/descriptor.rst
+14
-3
No files found.
Doc/howto/descriptor.rst
View file @
8c5c3e3b
...
@@ -218,25 +218,36 @@ here is a pure Python equivalent::
...
@@ -218,25 +218,36 @@ here is a pure Python equivalent::
self.fget = fget
self.fget = fget
self.fset = fset
self.fset = fset
self.fdel = fdel
self.fdel = fdel
if doc is None and fget is not None:
doc = fget.__doc__
self.__doc__ = doc
self.__doc__ = doc
def __get__(self, obj, objtype=None):
def __get__(self, obj, objtype=None):
if obj is None:
if obj is None:
return self
return self
if self.fget is None:
if self.fget is None:
raise AttributeError
, "unreadable attribute"
raise AttributeError
("unreadable attribute")
return self.fget(obj)
return self.fget(obj)
def __set__(self, obj, value):
def __set__(self, obj, value):
if self.fset is None:
if self.fset is None:
raise AttributeError
, "can't set attribute"
raise AttributeError
("can't set attribute")
self.fset(obj, value)
self.fset(obj, value)
def __delete__(self, obj):
def __delete__(self, obj):
if self.fdel is None:
if self.fdel is None:
raise AttributeError
, "can't delete attribute"
raise AttributeError
("can't delete attribute")
self.fdel(obj)
self.fdel(obj)
def getter(self, fget):
return type(self)(fget, self.fset, self.fdel, self.__doc__)
def setter(self, fset):
return type(self)(self.fget, fset, self.fdel, self.__doc__)
def deleter(self, fdel):
return type(self)(self.fget, self.fset, fdel, self.__doc__)
The :func:`property` builtin helps whenever a user interface has granted
The :func:`property` builtin helps whenever a user interface has granted
attribute access and then subsequent changes require the intervention of a
attribute access and then subsequent changes require the intervention of a
method.
method.
...
...
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