Skip to content

Commit 2453048

Browse files
committed
Removal of six dependency
1 parent 34d6314 commit 2453048

47 files changed

Lines changed: 250 additions & 241 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.travis.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ python:
88

99
# command to install dependencies
1010
install:
11-
- pip install six==1.9.0
1211
- pip install nose-exclude
1312

1413
# command to run tests

‎backtrader/analyzer.py‎

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

2424
import pprint as pp
2525

26-
import six
26+
from .utils.py3 import with_metaclass
2727

2828
from backtrader import MetaParams, Strategy, WriterFile
2929
import backtrader.metabase as metabase
@@ -77,7 +77,7 @@ def dopostinit(cls, _obj, *args, **kwargs):
7777
return _obj, args, kwargs
7878

7979

80-
class Analyzer(six.with_metaclass(MetaAnalyzer, object)):
80+
class Analyzer(with_metaclass(MetaAnalyzer, object)):
8181
csv = True
8282

8383
def __len__(self):

‎backtrader/analyzers/annualreturn.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from __future__ import (absolute_import, division, print_function,
2222
unicode_literals)
2323

24-
from six.moves import xrange
24+
from backtrader.utils.py3 import range
2525

2626
from backtrader import Analyzer, num2date
2727
from backtrader.utils import OrderedDict
@@ -58,7 +58,7 @@ def stop(self):
5858
self.rets = list()
5959
self.ret = OrderedDict()
6060

61-
for i in xrange(len(self.strategy.data)):
61+
for i in range(len(self.strategy.data)):
6262
dt = num2date(self.strategy.data.datetime.getzeroval(i))
6363

6464
value_cur = self.strategy.stats.broker.value.getzeroval(i)

‎backtrader/analyzers/sharpe.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import operator
2525

26-
from six.moves import map
26+
from backtrader.utils.py3 import map
2727

2828
from backtrader import Analyzer, TimeFrame
2929
from backtrader.mathsupport import average, standarddev

‎backtrader/broker.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323

2424
import collections
2525

26-
import six
26+
from .utils.py3 import with_metaclass
2727

2828
from .comminfo import CommissionInfo
2929
from .position import Position
3030
from .metabase import MetaParams
3131
from .order import Order, BuyOrder, SellOrder
3232

3333

34-
class BrokerBack(six.with_metaclass(MetaParams, object)):
34+
class BrokerBack(with_metaclass(MetaParams, object)):
3535

3636
params = (
3737
('cash', 10000.0),
@@ -44,7 +44,7 @@ def __init__(self):
4444
self.init()
4545

4646
def init(self):
47-
if None not in self.comminfo.keys():
47+
if None not in self.comminfo:
4848
self.comminfo = dict({None: self.p.commission})
4949

5050
self.startingcash = self.cash = self.p.cash
@@ -95,7 +95,7 @@ def cancel(self, order):
9595

9696
def getvalue(self, datas=None):
9797
pos_value = 0.0
98-
for data in datas or self.positions.keys():
98+
for data in datas or self.positions:
9999
comminfo = self.getcommissioninfo(data)
100100
position = self.positions[data]
101101
pos_value += comminfo.getvalue(position, data.close[0])

‎backtrader/btrun/btrun.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import string
3030
import sys
3131

32+
from backtrader.utils.py3 import range
33+
3234
import backtrader as bt
3335
import backtrader.feeds as btfeeds
3436
import backtrader.indicators as btinds
@@ -311,7 +313,7 @@ def parse_args(pargs=''):
311313
group.add_argument('--nostdstats', action='store_true',
312314
help='Disable the standard statistics observers')
313315

314-
datakeys = list(DATAFORMATS.keys())
316+
datakeys = list(DATAFORMATS)
315317
group.add_argument('--csvformat', '-c', required=False,
316318
default='btcsv', choices=datakeys,
317319
help='CSV Format')

‎backtrader/cerebro.py‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
import itertools
2626
import multiprocessing
2727

28-
import six
29-
from six.moves import map, xrange, zip
28+
from .utils.py3 import map, range, zip, with_metaclass, string_types
3029

3130
from .broker import BrokerBack
3231
from .metabase import MetaParams
@@ -36,7 +35,7 @@
3635
from .utils import OrderedDict
3736

3837

39-
class Cerebro(six.with_metaclass(MetaParams, object)):
38+
class Cerebro(with_metaclass(MetaParams, object)):
4039
'''
4140
Params:
4241
@@ -103,7 +102,7 @@ def iterize(iterable):
103102
'''
104103
niterable = list()
105104
for elem in iterable:
106-
if isinstance(elem, six.string_types):
105+
if isinstance(elem, string_types):
107106
elem = (elem,)
108107
elif not isinstance(elem, collections.Iterable):
109108
elem = (elem,)
@@ -171,7 +170,7 @@ def optstrategy(self, strategy, *args, **kwargs):
171170
172171
or
173172
174-
- cerebro.optstrategy(MyStrategy, period=xrange(15, 25))
173+
- cerebro.optstrategy(MyStrategy, period=range(15, 25))
175174
176175
This will execute MyStrategy with ``period`` values 15 -> 25 (25 not
177176
included in the lot)
@@ -194,7 +193,7 @@ def optstrategy(self, strategy, *args, **kwargs):
194193
args = self.iterize(args)
195194
optargs = itertools.product(*args)
196195

197-
optkeys = list(kwargs.keys()) # py2/3
196+
optkeys = list(kwargs)
198197

199198
vals = self.iterize(kwargs.values())
200199
optvals = itertools.product(*vals)
@@ -469,7 +468,7 @@ def _runonce(self, runstrats):
469468
# here again, because pointers are at 0
470469
data0 = self.datas[0]
471470
datas = self.datas[1:]
472-
for i in xrange(data0.buflen()):
471+
for i in range(data0.buflen()):
473472
data0.advance()
474473
for data in datas:
475474
data.advance(datamaster=data0)

‎backtrader/comminfo.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
from __future__ import (absolute_import, division, print_function,
2222
unicode_literals)
2323

24-
25-
import six
26-
24+
from .utils.py3 import with_metaclass
2725
from .metabase import MetaParams
2826

2927

30-
class CommissionInfo(six.with_metaclass(MetaParams)):
28+
class CommissionInfo(with_metaclass(MetaParams)):
3129
'''CommissionInfo
3230
3331
This class tries to cover commision schemes for elements which have a cost

‎backtrader/dataseries.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from __future__ import (absolute_import, division, print_function,
2222
unicode_literals)
2323

24-
from six.moves import xrange
24+
from .utils.py3 import range
2525

2626
from .lineseries import LineSeries
2727
from .import num2date
@@ -69,7 +69,7 @@ def getwritervalues(self):
6969
for line in self.LineOrder[1:]:
7070
values.append(self.lines[line][0])
7171

72-
for i in xrange(len(self.LineOrder), self.lines.size()):
72+
for i in range(len(self.LineOrder), self.lines.size()):
7373
values.append(self.lines[i][0])
7474

7575
return values

‎backtrader/feed.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import datetime
2525
import os.path
2626

27-
import six
27+
from .utils.py3 import with_metaclass, bytes
2828

2929
from . import dataseries
3030
from . import metabase
@@ -87,8 +87,8 @@ def dopostinit(cls, _obj, *args, **kwargs):
8787
return _obj, args, kwargs
8888

8989

90-
class AbstractDataBase(six.with_metaclass(MetaAbstractDataBase,
91-
dataseries.OHLCDateTime)):
90+
class AbstractDataBase(with_metaclass(MetaAbstractDataBase,
91+
dataseries.OHLCDateTime)):
9292
params = (('dataname', None),
9393
('fromdate', datetime.datetime.min),
9494
('todate', datetime.datetime.max),
@@ -224,7 +224,7 @@ class DataBase(AbstractDataBase):
224224
pass
225225

226226

227-
class FeedBase(six.with_metaclass(metabase.MetaParams, object)):
227+
class FeedBase(with_metaclass(metabase.MetaParams, object)):
228228
params = () + DataBase.params._gettuple()
229229

230230
def __init__(self):
@@ -269,7 +269,7 @@ def dopostinit(cls, _obj, *args, **kwargs):
269269
return _obj, args, kwargs
270270

271271

272-
class CSVDataBase(six.with_metaclass(MetaCSVDataBase, DataBase)):
272+
class CSVDataBase(with_metaclass(MetaCSVDataBase, DataBase)):
273273
'''
274274
Base class for classes implementing CSV DataFeeds
275275
@@ -296,6 +296,8 @@ def start(self):
296296
if self.p.headers:
297297
self.f.readline() # skip the headers
298298

299+
self.separator = bytes(self.p.separator)
300+
299301
def stop(self):
300302
if self.f is not None:
301303
self.f.close()
@@ -311,8 +313,8 @@ def _load(self):
311313
if not line:
312314
return False
313315

314-
line = line.rstrip(six.b('\r\n'))
315-
linetokens = line.split(six.b(self.p.separator))
316+
line = line.rstrip(b'\r\n')
317+
linetokens = line.split(self.separator)
316318
return self._loadline(linetokens)
317319

318320

0 commit comments

Comments
 (0)