Skip to content

Commit

Permalink
remove _compat asdf.open argument
Browse files Browse the repository at this point in the history
remove AsdfFile.open mention in docstring
  • Loading branch information
braingram committed Jul 17, 2023
1 parent 0c7d82f commit aff3b1d
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions asdf/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(
The URI for this ASDF file. Used to resolve relative
references against. If not provided, will be
automatically determined from the associated file object,
if possible and if created from `asdf.AsdfFile.open`.
if possible and if created from `asdf.open`.
extensions : object, optional
Additional extensions to use when reading and writing the file.
Expand Down Expand Up @@ -1619,24 +1619,6 @@ def _create_serialization_context(self):
return SerializationContext(self.version_string, self.extension_manager, self.uri, self._blocks)


def _check_and_set_mode(fileobj, asdf_mode):
if asdf_mode is not None and asdf_mode not in ["r", "rw"]:
msg = f"Unrecognized asdf mode '{asdf_mode}'. Must be either 'r' or 'rw'"
raise ValueError(msg)

if asdf_mode is None:
if isinstance(fileobj, io.IOBase):
return "rw" if fileobj.writable() else "r"

if isinstance(fileobj, generic_io.GenericFile):
return fileobj.mode

# This is the safest assumption for the default fallback
return "r"

return asdf_mode


_DEPRECATED_KWARG_TO_CONFIG_PROPERTY = {
"auto_inline": ("array_inline_threshold", lambda v: v),
"validate_on_read": ("validate_on_read", lambda v: v),
Expand Down Expand Up @@ -1672,7 +1654,6 @@ def open_asdf(
custom_schema=None,
strict_extension_check=False,
ignore_missing_extensions=False,
_compat=False,
**kwargs,
):
"""
Expand Down Expand Up @@ -1751,10 +1732,18 @@ def open_asdf(
The new AsdfFile object.
"""

# For now retain backwards compatibility with the old API behavior,
# specifically when being called from AsdfFile.open
if not _compat:
mode = _check_and_set_mode(fd, mode)
if mode is not None and mode not in ["r", "rw"]:
msg = f"Unrecognized asdf mode '{mode}'. Must be either 'r' or 'rw'"
raise ValueError(msg)

Check warning on line 1737 in asdf/asdf.py

View check run for this annotation

Codecov / codecov/patch

asdf/asdf.py#L1736-L1737

Added lines #L1736 - L1737 were not covered by tests

if mode is None:
if isinstance(fd, io.IOBase):
mode = "rw" if fd.writable() else "r"
elif isinstance(fd, generic_io.GenericFile):
mode = fd.mode
else:
# This is the safest assumption for the default fallback
mode = "r"

instance = AsdfFile(
ignore_version_mismatch=ignore_version_mismatch,
Expand Down

0 comments on commit aff3b1d

Please sign in to comment.