Skip to content

Commit

Permalink
Fix parameter naming in from_iter methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaiter committed May 26, 2016
1 parent 1b173c5 commit 3caf73f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions rust_fst/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def finish(self):


class FileMapBuilder(MapBuilder):
def __init__(self, fpath):
def __init__(self, path):
self._ctx = lib.fst_context_new()
self._writer_p = checked_call(
lib.fst_bufwriter_new, self._ctx, fpath.encode('utf8'))
lib.fst_bufwriter_new, self._ctx, path.encode('utf8'))
self._builder_p = checked_call(
lib.fst_filemapbuilder_new, self._ctx, self._writer_p)

Expand Down Expand Up @@ -122,7 +122,7 @@ class Map(object):

@staticmethod
@contextmanager
def build(fpath=None):
def build(path=None):
""" Context manager to build a new map.
Call :py:meth:`insert` on the returned builder object to insert
Expand All @@ -133,15 +133,15 @@ def build(fpath=None):
in memory
:returns: :py:class:`MapBuilder`
"""
if fpath:
builder = FileMapBuilder(fpath)
if path:
builder = FileMapBuilder(path)
else:
builder = MemMapBuilder()
yield builder
builder.finish()

@classmethod
def from_iter(cls, it, fpath=None):
def from_iter(cls, it, path=None):
""" Build a new map from an iterator.
Keep in mind that the iterator must return lexicographically sorted
Expand All @@ -157,11 +157,11 @@ def from_iter(cls, it, fpath=None):
"""
if isinstance(it, dict):
it = sorted(it.items(), key=lambda x: x[0])
with cls.build(fpath) as builder:
with cls.build(path) as builder:
for key, val in it:
builder.insert(key, val)
if fpath:
return cls(path=fpath)
if path:
return cls(path=path)
else:
return builder.get_map()

Expand Down
18 changes: 9 additions & 9 deletions rust_fst/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def finish(self):


class FileSetBuilder(SetBuilder):
def __init__(self, fpath):
def __init__(self, path):
self._ctx = lib.fst_context_new()
self._writer_p = checked_call(
lib.fst_bufwriter_new, self._ctx, fpath.encode('utf8'))
lib.fst_bufwriter_new, self._ctx, path.encode('utf8'))
self._builder_p = checked_call(
lib.fst_filesetbuilder_new, self._ctx, self._writer_p)

Expand Down Expand Up @@ -113,7 +113,7 @@ class Set(object):

@staticmethod
@contextmanager
def build(fpath=None):
def build(path=None):
""" Context manager to build a new set.
Call :py:meth:`insert` on the returned builder object to insert
Expand All @@ -124,15 +124,15 @@ def build(fpath=None):
in memory
:returns: :py:class:`SetBuilder`
"""
if fpath:
builder = FileSetBuilder(fpath)
if path:
builder = FileSetBuilder(path)
else:
builder = MemSetBuilder()
yield builder
builder.finish()

@classmethod
def from_iter(cls, it, fpath=None):
def from_iter(cls, it, path=None):
""" Build a new set from an iterator.
Keep in mind that the iterator must return unicode strings in
Expand All @@ -145,11 +145,11 @@ def from_iter(cls, it, fpath=None):
:returns: The finished set
:rtype: :py:class:`Set`
"""
with cls.build(fpath) as builder:
with cls.build(path) as builder:
for key in it:
builder.insert(key)
if fpath:
return cls(path=fpath)
if path:
return cls(path=path)
else:
return builder.get_set()

Expand Down

0 comments on commit 3caf73f

Please sign in to comment.