Skip to content

Commit

Permalink
remove ctx arg from reserve_blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Apr 24, 2023
1 parent 11159ad commit 93c2eac
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions asdf/_tests/test_block_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def from_yaml_tree(self, node, tag, ctx):
ctx.assign_block_key(block_index, key2)
return obj

def reserve_blocks(self, obj, tag, ctx): # Is there a ctx or tag at this point?
def reserve_blocks(self, obj, tag):
if self._return_invalid_keys:
# return something unhashable
self._return_invalid_keys = False
Expand Down Expand Up @@ -162,7 +162,7 @@ def from_yaml_tree(self, node, tag, ctx):
ctx.assign_block_key(block_index, obj._asdf_key)
return obj

def reserve_blocks(self, obj, tag, ctx):
def reserve_blocks(self, obj, tag):
return [obj._asdf_key]


Expand Down
2 changes: 1 addition & 1 deletion asdf/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def _find_used_blocks(self, tree, ctx, remove=True):
converter = ctx.extension_manager.get_converter_for_type(type(node))
sctx = ctx._create_serialization_context()
tag = converter.select_tag(node, sctx)
for key in converter.reserve_blocks(node, tag, sctx):
for key in converter.reserve_blocks(node, tag):
reserved_blocks.add(self.find_or_create_block(key))
else:
hook = ctx._type_index.get_hook_for_type("reserve_blocks", type(node), ctx.version_string)
Expand Down
10 changes: 3 additions & 7 deletions asdf/extension/_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def from_yaml_tree(self, node, tag, ctx):
or a generator that yields such an instance.
"""

def reserve_blocks(self, obj, tag, ctx):
def reserve_blocks(self, obj, tag):
"""
Reserve any number of blocks in which data (ndarrays) can be
stored.
Expand All @@ -165,8 +165,6 @@ def reserve_blocks(self, obj, tag, ctx):
The tag identifying the YAML type that ``obj`` should be
converted into. Selected by a call to this converter's
select_tag method.
ctx : asdf.asdf.SerializationContext
The context of the current serialization request.
Returns
-------
Expand Down Expand Up @@ -303,7 +301,7 @@ def from_yaml_tree(self, node, tag, ctx):
"""
return self._delegate.from_yaml_tree(node, tag, ctx)

def reserve_blocks(self, obj, tag, ctx):
def reserve_blocks(self, obj, tag):
"""
Reserve blocks to be used during conversion of this object
Expand All @@ -317,8 +315,6 @@ def reserve_blocks(self, obj, tag, ctx):
The tag identifying the YAML type that ``obj`` should be
converted into. Selected by a call to this converter's
select_tag method.
ctx : asdf.asdf.SerializationContext
The context of the current serialization request.
Returns
-------
Expand All @@ -327,7 +323,7 @@ def reserve_blocks(self, obj, tag, ctx):
"""
if hasattr(self._delegate, "reserve_blocks"):
return self._delegate.reserve_blocks(obj, tag, ctx)
return self._delegate.reserve_blocks(obj, tag)
return []

@property
Expand Down
2 changes: 1 addition & 1 deletion docs/asdf/extending/converters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ A simple example of a Converter using block storage to store the ``payload`` for
obj.payload = ctx.get_block_data_callback(block_index)()
return obj

def reserve_blocks(self, obj, tag, ctx):
def reserve_blocks(self, obj, tag):
return [obj._asdf_key]

class BlockExtension(Extension):
Expand Down

0 comments on commit 93c2eac

Please sign in to comment.