-
-
Notifications
You must be signed in to change notification settings - Fork 647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add future lib and port src/base #6067
Changes from all commits
31167f9
06b0db0
0c0e8f7
ce2216b
77ae991
7f07f94
8bc62a4
70d2547
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
unicode_literals, with_statement) | ||
|
||
import pprint | ||
from builtins import object | ||
|
||
import pystache | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import hashlib | ||
import json | ||
from builtins import object | ||
|
||
|
||
def hash_all(strs, digest=None): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import os | ||
import pkgutil | ||
from builtins import object | ||
|
||
import pystache | ||
import six | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import functools | ||
import threading | ||
from builtins import object | ||
|
||
|
||
class Storage(threading.local): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,13 @@ | |
unicode_literals, with_statement) | ||
|
||
import re | ||
from itertools import izip_longest | ||
from builtins import map, object, str | ||
from functools import total_ordering | ||
|
||
from future.moves.itertools import zip_longest | ||
|
||
|
||
@total_ordering | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implements all 6 comparison dunders, given There is a slight performance penalty. If |
||
class Revision(object): | ||
"""Represents a software revision that is comparable to another revision describing the same | ||
software. | ||
|
@@ -74,7 +78,7 @@ def lenient(cls, rev): | |
""" | ||
rev = re.sub(r'(\d)([a-zA-Z])', r'\1.\2', rev) | ||
rev = re.sub(r'([a-zA-Z])(\d)', r'\1.\2', rev) | ||
return cls(*map(cls._parse_atom, re.split(r'[.+_\-]', rev))) | ||
return cls(*list(map(cls._parse_atom, re.split(r'[.+_\-]', rev)))) | ||
|
||
def __init__(self, *components): | ||
self._components = components | ||
|
@@ -87,21 +91,26 @@ def components(self): | |
""" | ||
return list(self._components) | ||
|
||
def __cmp__(self, other): | ||
for ours, theirs in izip_longest(self._components, other._components, fillvalue=0): | ||
difference = cmp(ours, theirs) | ||
if difference != 0: | ||
return difference | ||
return 0 | ||
def _is_valid_operand(self, other): | ||
return hasattr(other, '_components') | ||
|
||
def __repr__(self): | ||
return '{}({})'.format(self.__class__.__name__, ', '.join(map(repr, self._components))) | ||
|
||
def __eq__(self, other): | ||
return hasattr(other, '_components') and tuple(self._components) == tuple(other._components) | ||
|
||
def __ne__(self, other): | ||
return not self.__eq__(other) | ||
if not self._is_valid_operand(other): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This slightly changes the behavior from before. When comparing to non-Revisions, this returns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any python3 compat reason to mix in this behavior change? As an example of future conversion PRs, it would be good to stick to pure semantic-preserving automated conversion if possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I made the change is for the The only Py3 change we need is replacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer it if just to keep semantics changes out of the conversion PRs. Especially since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reverted But am keeping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I think I can buy the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was mistaken there. The semantic shift is subtle to non-existant depending on how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay I reverted everything back to identical semantics from before (just more explicit). I think it's a good policy to avoid any changes in these PRs because they get buried. Instead, will add notes in form |
||
return False # TODO(python3port): typically this should return NotImplemented. | ||
# Returning False for now to avoid changing prior API. | ||
return tuple(self._components) == tuple(other._components) | ||
|
||
def __lt__(self, other): | ||
if not self._is_valid_operand(other): | ||
return AttributeError # TODO(python3port): typically this should return NotImplemented. | ||
# Returning AttributeError for now to avoid changing prior API. | ||
for ours, theirs in zip_longest(self._components, other._components, fillvalue=0): | ||
if ours != theirs: | ||
return ours < theirs | ||
return False | ||
|
||
def __hash__(self): | ||
return hash(self._components) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a tough bug to find. Pystache by default uses
cgi.escape()
in Python2, buthtml.escape()
in Python3. Becausefuture
adds a backport tohtml
(which doesn't exist in Python2), Pystache successfully was importing the module and usinghtml.escape()
.html.escape()
escapes'
unlikecgi.escape()
, so one of our tests was failing.For now, I'm having us stay with the old semantics.