Skip to content

Commit 6f50bbf

Browse files
committed
Merge branch 'v0.13.x' of https://github.com/PythonCharmers/python-future into v0.13.x
2 parents 92d14f2 + cefd694 commit 6f50bbf

File tree

15 files changed

+224
-25
lines changed

15 files changed

+224
-25
lines changed

docs/notebooks/Writing Python 2-3 compatible code.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:2e4d4d39759584d5af9864c83f87e39a16b6886cc4be686dad47731f13131d90"
4+
"signature": "sha256:4569bf2488b392f4d95eda8d1f5069a4b57beeefd63826b664af5e734716438f"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -24,9 +24,9 @@
2424
"- **Author:** Ed Schofield.\n",
2525
"- **Licence:** Creative Commons Attribution.\n",
2626
"\n",
27-
"This notebook shows you idioms for writing future-proof code that is compatible with both versions of Python: 2 and 3.\n",
27+
"A PDF version is here: http://python-future.org/compatible_idioms.pdf\n",
2828
"\n",
29-
"It accompanies Ed Schofield's talk at PyCon AU 2014, \"Writing 2/3 compatible code\".\n",
29+
"This notebook shows you idioms for writing future-proof code that is compatible with both versions of Python: 2 and 3. It accompanies Ed Schofield's talk at PyCon AU 2014, \"Writing 2/3 compatible code\".\n",
3030
"\n",
3131
"Minimum versions:\n",
3232
"\n",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
A script to re-enable colour in .html files produced from IPython notebooks.
6+
7+
Based on a script in a GitHub gist with this copyright notice:
8+
9+
#----------------------------------------------------------------------------
10+
# Copyright (c) 2013 - Damián Avila
11+
#
12+
# Distributed under the terms of the Modified BSD License.
13+
#
14+
# A little snippet to fix @media print issue printing slides from IPython
15+
#-----------------------------------------------------------------------------
16+
"""
17+
18+
import io
19+
import sys
20+
21+
notebook = sys.argv[1]
22+
assert notebook.endswith('.html')
23+
# notebook = 'jevans.ipynb'
24+
path = notebook[:-5] + '.html'
25+
flag = u'@media print{*{text-shadow:none !important;color:#000 !important'
26+
27+
with io.open(path, 'r') as in_file:
28+
data = in_file.readlines()
29+
for i, line in enumerate(data):
30+
if line[:64] == flag:
31+
data[i] = data[i].replace('color:#000 !important;', '')
32+
33+
with io.open(path, 'w') as out_file:
34+
out_file.writelines(data)
35+
36+
print("You can now print your slides")

future/tests/test_bytes.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,33 @@ def test_mod(self):
600600
with self.assertRaises(TypeError):
601601
bytes(b'%r' % 'abc')
602602

603+
@expectedFailurePY2
604+
def test_multiple_inheritance(self):
605+
"""
606+
Issue #96 (for newbytes instead of newobject)
607+
"""
608+
import collections
609+
610+
class Base(bytes):
611+
pass
612+
613+
class Foo(Base, collections.Container):
614+
def __contains__(self, item):
615+
return False
616+
617+
@expectedFailurePY2
618+
def test_with_metaclass_and_bytes(self):
619+
"""
620+
Issue #91 (for newdict instead of newobject)
621+
"""
622+
from future.utils import with_metaclass
623+
624+
class MetaClass(type):
625+
pass
626+
627+
class TestClass(with_metaclass(MetaClass, bytes)):
628+
pass
629+
603630

604631
if __name__ == '__main__':
605632
unittest.main()

future/tests/test_dict.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,34 @@ def test_braces_create_newdict_object(self):
106106
d = self.d1
107107
self.assertTrue(type(d) == dict)
108108

109+
@expectedFailurePY2
110+
def test_multiple_inheritance(self):
111+
"""
112+
Issue #96 (for newdict instead of newobject)
113+
"""
114+
import collections
115+
116+
class Base(dict):
117+
pass
118+
119+
class Foo(Base, collections.Container):
120+
def __contains__(self, item):
121+
return False
122+
123+
@expectedFailurePY2
124+
def test_with_metaclass_and_dict(self):
125+
"""
126+
Issue #91 (for newdict instead of newobject)
127+
"""
128+
from future.utils import with_metaclass
129+
130+
class MetaClass(type):
131+
pass
132+
133+
class TestClass(with_metaclass(MetaClass, dict)):
134+
pass
135+
136+
109137

110138
if __name__ == '__main__':
111139
unittest.main()

future/tests/test_int.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,33 @@ class myint(int):
10381038
self.assertRaises(TypeError, myint.from_bytes, mytype(0), 'big')
10391039
# self.assertRaises(TypeError, int.from_bytes, mytype(0), 'big', True)
10401040

1041+
@expectedFailurePY2
1042+
def test_multiple_inheritance(self):
1043+
"""
1044+
Issue #96 (for newint instead of newobject)
1045+
"""
1046+
import collections
1047+
1048+
class Base(int):
1049+
pass
1050+
1051+
class Foo(Base, collections.Container):
1052+
def __add__(self, other):
1053+
return 0
1054+
1055+
@expectedFailurePY2
1056+
def test_with_metaclass_and_int(self):
1057+
"""
1058+
Issue #91 (for newint instead of newobject)
1059+
"""
1060+
from future.utils import with_metaclass
1061+
1062+
class MetaClass(type):
1063+
pass
1064+
1065+
class TestClass(with_metaclass(MetaClass, int)):
1066+
pass
1067+
10411068

10421069
if __name__ == "__main__":
10431070
unittest.main()

future/tests/test_list.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import absolute_import, unicode_literals, print_function
77
from future.builtins import *
88
from future import utils
9-
from future.tests.base import unittest
9+
from future.tests.base import unittest, expectedFailurePY2
1010

1111

1212
class TestList(unittest.TestCase):
@@ -157,6 +157,33 @@ def test_bool(self):
157157
l2.clear()
158158
self.assertFalse(bool(l2))
159159

160+
@expectedFailurePY2
161+
def test_multiple_inheritance(self):
162+
"""
163+
Issue #96 (for newdict instead of newobject)
164+
"""
165+
import collections
166+
167+
class Base(list):
168+
pass
169+
170+
class Foo(Base, collections.Container):
171+
def __contains__(self, item):
172+
return False
173+
174+
@expectedFailurePY2
175+
def test_with_metaclass_and_list(self):
176+
"""
177+
Issue #91 (for newdict instead of newobject)
178+
"""
179+
from future.utils import with_metaclass
180+
181+
class MetaClass(type):
182+
pass
183+
184+
class TestClass(with_metaclass(MetaClass, list)):
185+
pass
186+
160187

161188
if __name__ == '__main__':
162189
unittest.main()

future/tests/test_object.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from future import utils
88
from future.builtins import object, str, next, int, super
99
from future.utils import implements_iterator, python_2_unicode_compatible
10-
from future.tests.base import unittest
10+
from future.tests.base import unittest, expectedFailurePY2
1111

1212

1313
class TestNewObject(unittest.TestCase):
@@ -162,6 +162,7 @@ class C(A):
162162
self.assertFalse(isinstance(b, C))
163163
self.assertTrue(isinstance(c, C))
164164

165+
@expectedFailurePY2
165166
def test_types_isinstance_newobject(self):
166167
a = list()
167168
b = dict()
@@ -204,6 +205,31 @@ def __int__(self):
204205
if utils.PY2:
205206
self.assertEqual(long(a), 0)
206207

208+
def test_multiple_inheritance(self):
209+
"""
210+
Issue #96
211+
"""
212+
import collections
213+
214+
class Base(object):
215+
pass
216+
217+
class Foo(Base, collections.Container):
218+
def __contains__(self, item):
219+
return False
220+
221+
def test_with_metaclass_and_object(self):
222+
"""
223+
Issue #91
224+
"""
225+
from future.utils import with_metaclass
226+
227+
class MetaClass(type):
228+
pass
229+
230+
class TestClass(with_metaclass(MetaClass, object)):
231+
pass
232+
207233

208234
if __name__ == '__main__':
209235
unittest.main()

future/tests/test_str.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import absolute_import, unicode_literals, print_function
77
from future.builtins import *
88
from future import utils
9-
from future.tests.base import unittest
9+
from future.tests.base import unittest, expectedFailurePY2
1010

1111
import os
1212

@@ -524,6 +524,33 @@ def test_maketrans_translate(self):
524524
self.assertRaises(TypeError, 'hello'.translate)
525525
self.assertRaises(TypeError, 'abababc'.translate, 'abc', 'xyz')
526526

527+
@expectedFailurePY2
528+
def test_multiple_inheritance(self):
529+
"""
530+
Issue #96 (for newstr instead of newobject)
531+
"""
532+
import collections
533+
534+
class Base(str):
535+
pass
536+
537+
class Foo(Base, collections.Container):
538+
def __contains__(self, item):
539+
return False
540+
541+
@expectedFailurePY2
542+
def test_with_metaclass_and_str(self):
543+
"""
544+
Issue #91 (for newstr instead of newobject)
545+
"""
546+
from future.utils import with_metaclass
547+
548+
class MetaClass(type):
549+
pass
550+
551+
class TestClass(with_metaclass(MetaClass, str)):
552+
pass
553+
527554

528555
if __name__ == '__main__':
529556
unittest.main()

future/types/newbytes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from future.utils import istext, isbytes, PY3, with_metaclass
1313
from future.types import no, issubset
14-
from future.types.newobject import newobject, BaseNewObject
14+
from future.types.newobject import newobject
1515

1616

1717
_builtin_bytes = bytes
@@ -21,7 +21,7 @@
2121
unicode = str
2222

2323

24-
class BaseNewBytes(BaseNewObject):
24+
class BaseNewBytes(type):
2525
def __instancecheck__(cls, instance):
2626
if cls == newbytes:
2727
return isinstance(instance, _builtin_bytes)

future/types/newdict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
import sys
2020

2121
from future.utils import with_metaclass
22-
from future.types.newobject import newobject, BaseNewObject
22+
from future.types.newobject import newobject
2323

2424

2525
_builtin_dict = dict
2626
ver = sys.version_info[:2]
2727

2828

29-
class BaseNewDict(BaseNewObject):
29+
class BaseNewDict(type):
3030
def __instancecheck__(cls, instance):
3131
if cls == newdict:
3232
return isinstance(instance, _builtin_dict)

0 commit comments

Comments
 (0)