Skip to content

Commit

Permalink
Merge pull request #652 from MDAnalysis/issue-649
Browse files Browse the repository at this point in the history
Removed inheritance of basestring from NamedStream
  • Loading branch information
jbarnoud committed Jan 22, 2016
2 parents bff7415 + c45daa8 commit 5dc4fde
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Enhancement
Changes

* xdrlib has been ported to cython. (Issue #441)
* util.NamedStream no longer inherits from basestring (Issue #649)

Fixes
* ContactAnalysis1 run method now starts at frame index 0 by deafult (Issue #624)
Expand Down
18 changes: 4 additions & 14 deletions package/MDAnalysis/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
import warnings
from functools import wraps
import numpy as np
import functools

from ..exceptions import StreamWarning

Expand Down Expand Up @@ -458,7 +459,8 @@ def is_exe(fpath):
return None


class NamedStream(io.IOBase, basestring):
@functools.total_ordering
class NamedStream(io.IOBase):
"""Stream that also provides a (fake) name.
By wrapping a stream *stream* in this class, it can be passed to
Expand Down Expand Up @@ -721,21 +723,9 @@ def __getitem__(self, x):
def __eq__(self, x):
return self.name == x

def __neq__(self, x):
return self.name != x

def __gt__(self, x):
return self.name > x

def __ge__(self, x):
return self.name >= x

def __lt__(self, x):
return self.name < x

def __le__(self, x):
return self.name <= x

def __len__(self):
return len(self.name)

Expand Down Expand Up @@ -835,7 +825,7 @@ def guess_format(filename):

def iterable(obj):
"""Returns ``True`` if *obj* can be iterated over and is *not* a string."""
if isinstance(obj, basestring):
if isinstance(obj, (basestring, NamedStream)):
return False # avoid iterating over characters of a string

if hasattr(obj, 'next'):
Expand Down

0 comments on commit 5dc4fde

Please sign in to comment.