Migrate codebase to Python 3#3
Conversation
| return constraint.limit.evaluate(context) | ||
| return value | ||
|
|
||
| def _sequence_int_value(self, value): |
| from functools import cmp_to_key | ||
|
|
||
|
|
||
| def cmp(a, b): |
There was a problem hiding this comment.
cmd is a very general function; why do we need this?
|
|
||
| class ShouldEndType(IntegerType): | ||
| """Parameter used to pass the 'should end' up to the parent.""" | ||
| def __hash__(self): |
There was a problem hiding this comment.
Why do we need this to be hashable?
| import bdec.output | ||
| import bdec.sequence as seq | ||
| import bdec.sequenceof as sof | ||
| from functools import reduce |
There was a problem hiding this comment.
Was reduce a built in, but no longer?
| return False | ||
|
|
||
| def to_file(items, output, encoding="utf-8", verbose=False): | ||
| def to_open(items, output, encoding="utf-8", verbose=False): |
There was a problem hiding this comment.
This is a bad rename; keep it as to_file. Better perhaps would be write_to_file, but let's keep that change out for this change for now.
| # As gzip'ed files seek extremely poorly, we'll read the file completely into memory. | ||
| import gzip | ||
| datafile = StringIO.StringIO(gzip.GzipFile(data_filename, 'rb').read()) | ||
| datafile = io.StringIO(gzip.GzipFile(data_filename, 'rb').read().decode('latin1')) |
There was a problem hiding this comment.
should datafile be binary, not a string?
| results.append((is_starting, entry)) | ||
| except ConstraintError, ex: | ||
| pass | ||
| except ConstraintError as caught: |
There was a problem hiding this comment.
why not use 'ex' here? Why use a temporary 'caught' which then gets renamed?
| def __init__(self, buffer): | ||
| assert isinstance(buffer, str), "Expected a string; got %s!" % repr(buffer) | ||
| buffer = _to_text_bytes(buffer) | ||
| assert isinstance(buffer, str), "Expected a string/bytes; got %s!" % repr(buffer) |
There was a problem hiding this comment.
we should just expect bytes now...
| encoding -- The unicode encoding the data is in. """ | ||
| try: | ||
| return unicode(self.bytes(), encoding) | ||
| return self.bytes().encode('latin1').decode(encoding) |
There was a problem hiding this comment.
for all locations like this where it uses latin1, it should be bytes
| def __str__(self): | ||
| return "Missing context '%s' (have %s)" % (self.name, | ||
| ', '.join("'%s'" % k for k in self.context.keys())) | ||
| ', '.join("'%s'" % k for k in list(self.context.keys()))) |
There was a problem hiding this comment.
do we need a list here? We're just iterating over it?
|
|
||
| def __div__(self, other): | ||
| return ArithmeticExpression(operator.div, self, other) | ||
| def __truediv__(self, other): |
There was a problem hiding this comment.
remind me, what's the difference with truediv?
| result = {} | ||
| regression_dir = os.path.dirname(__file__) | ||
| for name in os.listdir(regression_dir): | ||
| if name.startswith('__'): |
There was a problem hiding this comment.
This looks magic... what's it here for?
cd67484 to
113ba0a
Compare
No description provided.