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
caa9f437
Commit
caa9f437
authored
Aug 30, 2001
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add testcases for inheritance from tricky builtins (numbers, strings,
tuples).
parent
6fb3fdec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
0 deletions
+74
-0
Lib/test/test_descr.py
Lib/test/test_descr.py
+74
-0
No files found.
Lib/test/test_descr.py
View file @
caa9f437
...
@@ -1120,6 +1120,79 @@ def supers():
...
@@ -1120,6 +1120,79 @@ def supers():
verify
(
D
().
meth
(
4
)
==
"D(4)C(4)B(4)A(4)"
)
verify
(
D
().
meth
(
4
)
==
"D(4)C(4)B(4)A(4)"
)
def
inherits
():
if
verbose
:
print
"Testing inheritance from basic types..."
class
hexint
(
int
):
def
__repr__
(
self
):
return
hex
(
self
)
def
__add__
(
self
,
other
):
return
hexint
(
int
.
__add__
(
self
,
other
))
# (Note that overriding __radd__ doesn't work,
# because the int type gets first dibs.)
verify
(
repr
(
hexint
(
7
)
+
9
)
==
"0x10"
)
verify
(
repr
(
hexint
(
1000
)
+
7
)
==
"0x3ef"
)
class
octlong
(
long
):
__slots__
=
[]
def
__str__
(
self
):
s
=
oct
(
self
)
if
s
[
-
1
]
==
'L'
:
s
=
s
[:
-
1
]
return
s
def
__add__
(
self
,
other
):
return
self
.
__class__
(
super
(
octlong
,
self
).
__add__
(
other
))
__radd__
=
__add__
verify
(
str
(
octlong
(
3
)
+
5
)
==
"010"
)
# (Note that overriding __radd__ here only seems to work
# because the example uses a short int left argument.)
verify
(
str
(
5
+
octlong
(
3000
))
==
"05675"
)
class
precfloat
(
float
):
__slots__
=
[
'prec'
]
def
__init__
(
self
,
value
=
0.0
,
prec
=
12
):
self
.
prec
=
int
(
prec
)
float
.
__init__
(
value
)
def
__repr__
(
self
):
return
"%.*g"
%
(
self
.
prec
,
self
)
verify
(
repr
(
precfloat
(
1.1
))
==
"1.1"
)
class
madtuple
(
tuple
):
_rev
=
None
def
rev
(
self
):
if
self
.
_rev
is
not
None
:
return
self
.
_rev
L
=
list
(
self
)
L
.
reverse
()
self
.
_rev
=
self
.
__class__
(
L
)
return
self
.
_rev
a
=
madtuple
((
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0
))
verify
(
a
.
rev
()
==
madtuple
((
0
,
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
)))
verify
(
a
.
rev
().
rev
()
==
madtuple
((
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
0
)))
for
i
in
range
(
512
):
t
=
madtuple
(
range
(
i
))
u
=
t
.
rev
()
v
=
u
.
rev
()
verify
(
v
==
t
)
class
madstring
(
str
):
_rev
=
None
def
rev
(
self
):
if
self
.
_rev
is
not
None
:
return
self
.
_rev
L
=
list
(
self
)
L
.
reverse
()
self
.
_rev
=
self
.
__class__
(
""
.
join
(
L
))
return
self
.
_rev
s
=
madstring
(
"abcdefghijklmnopqrstuvwxyz"
)
verify
(
s
.
rev
()
==
madstring
(
"zyxwvutsrqponmlkjihgfedcba"
))
verify
(
s
.
rev
().
rev
()
==
madstring
(
"abcdefghijklmnopqrstuvwxyz"
))
for
i
in
range
(
256
):
s
=
madstring
(
""
.
join
(
map
(
chr
,
range
(
i
))))
t
=
s
.
rev
()
u
=
t
.
rev
()
verify
(
u
==
s
)
def
all
():
def
all
():
lists
()
lists
()
dicts
()
dicts
()
...
@@ -1151,6 +1224,7 @@ def all():
...
@@ -1151,6 +1224,7 @@ def all():
weakrefs
()
weakrefs
()
getsets
()
getsets
()
supers
()
supers
()
inherits
()
all
()
all
()
...
...
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