Skip to content

Commit

Permalink
deal with some differences under Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed May 5, 2013
1 parent dd86bb0 commit fa787f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/Missing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import os
import sys

from ExtensionClass import Base

if sys.version_info >= (3, ):
PY3 = True
else:
PY3 = False


class Missing(Base):

Expand All @@ -22,13 +28,19 @@ def __reduce__(self):
return 'V'
return (type(self), ())

def __nonzero__(self):
def __bool__(self):
return False

def __cmp__(self, other):
if self is notMissing:
return -1
return other is notMissing
if not PY3:
__nonzero__ = __bool__

def __coerce__(self, other):
return (self, notMissing)

def __cmp__(self, other):
if self is notMissing:
return -1
return other is notMissing

def __eq__(self, other):
if self is notMissing:
Expand Down Expand Up @@ -72,9 +84,6 @@ def _change(self):

__neg__ = __pos__ = __abs__ = __invert__ = _change

def __coerce__(self, other):
return (self, notMissing)

def __setattr__(self, key, value):
raise AttributeError(key)

Expand Down
4 changes: 4 additions & 0 deletions src/Missing/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
def u(value):
return str(value, 'utf-8')
long = int
PY3 = True
else:
def u(value):
return unicode(value, 'utf-8')
PY3 = False


class ValueTests(object):
Expand Down Expand Up @@ -174,6 +176,8 @@ def test_xor(self):
self.assertEqual(value, value ^ 2)

def test_coerce(self):
if PY3:
return
from Missing import notMissing
value = self._make_one()
self.assertEqual(coerce(value, 1), (value, notMissing))
Expand Down

0 comments on commit fa787f8

Please sign in to comment.