Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions python-spec/src/somacore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@

from .base import SOMAObject
from .collection import Collection
from .coordinates import AffineTransform
from .coordinates import Axis
from .coordinates import CoordinateSpace
from .coordinates import CoordinateTransform
from .coordinates import IdentityTransform
from .coordinates import ScaleTransform
from .coordinates import UniformScaleTransform
from .data import DataFrame
from .data import DenseNDArray
from .data import NDArray
Expand All @@ -32,7 +28,6 @@
from .experiment import Experiment
from .measurement import Measurement
from .options import BatchSize
from .options import IOfN
from .options import ResultOrder
from .query import AxisColumnNames
from .query import AxisQuery
Expand Down Expand Up @@ -68,7 +63,6 @@
"Experiment",
"Measurement",
"Scene",
"ImageProperties",
"MultiscaleImage",
"GeometryDataFrame",
"PointCloudDataFrame",
Expand All @@ -82,8 +76,4 @@
"Axis",
"CoordinateSpace",
"CoordinateTransform",
"AffineTransform",
"ScaleTransform",
"UniformScaleTransform",
"IdentityTransform",
)
100 changes: 0 additions & 100 deletions python-spec/src/somacore/_mixin.py

This file was deleted.

70 changes: 16 additions & 54 deletions python-spec/src/somacore/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@

from __future__ import annotations

import abc
from typing import Any, ClassVar, MutableMapping
from typing import Any, MutableMapping, runtime_checkable

from typing_extensions import LiteralString, Self
from typing_extensions import Protocol, Self

from . import options
from . import types


class SOMAObject(metaclass=abc.ABCMeta):
@runtime_checkable
class SOMAObject(Protocol):
"""The base type for all SOMA objects, containing common behaviors."""

__slots__ = ("__weakref__",)

@classmethod
@abc.abstractmethod
def open(
cls,
uri: str,
Expand All @@ -41,10 +38,9 @@ def open(
Returns: The SOMA object, opened for reading.
Lifecycle: maturing
"""
raise NotImplementedError()
...

@classmethod
@abc.abstractmethod
def exists(cls, uri: str, *, context: Any | None = None) -> bool:
"""Checks whether a SOMA object of this type is stored at the URI.

Expand All @@ -56,16 +52,15 @@ def exists(cls, uri: str, *, context: Any | None = None) -> bool:
False if the object does not exist, or is of a different type.
Lifecycle: maturing
"""
raise NotImplementedError()
...

@property
@abc.abstractmethod
def uri(self) -> str:
"""The URI of this SOMA object.

Lifecycle: maturing
"""
raise NotImplementedError()
...

@property
def context(self) -> types.ContextBase | None:
Expand All @@ -81,10 +76,9 @@ def context(self) -> types.ContextBase | None:

Lifecycle: maturing
"""
return None
...

@property
@abc.abstractmethod
def metadata(self) -> MutableMapping[str, Any]:
"""The metadata of this SOMA object.

Expand All @@ -94,35 +88,23 @@ def metadata(self) -> MutableMapping[str, Any]:

Lifecycle: maturing
"""
raise NotImplementedError()
...

@property
@abc.abstractmethod
def mode(self) -> options.OpenMode:
"""Returns the mode this object was opened in, either ``r`` or ``w``.

Lifecycle: maturing
"""
raise NotImplementedError()
...

@property
@abc.abstractmethod
def closed(self) -> bool:
"""True if this object has been closed; False if still open.

Lifecycle: maturing
"""
raise NotImplementedError()

soma_type: ClassVar[LiteralString]
"""A string describing the SOMA type of this object. This is constant.

This uses ClassVar since you can't do abstract class properties.
This is the equivalent, just without abc-based automatic verification.
Overrides are marked Final with an ignore[misc] because mypy by default
wants this to be mutable, and doesn't like overriding the mutable member
with a Final member.
"""
...

# Context management

Expand All @@ -138,28 +120,8 @@ def close(self) -> None:

Lifecycle: maturing
"""
# Default implementation does nothing.

def __enter__(self) -> Self:
return self

def __exit__(self, *_: Any) -> None:
self.close()

def __del__(self) -> None:
self.close()
super_del = getattr(super(), "__del__", lambda: None)
super_del()

# Explicitly use Python's identity-based equality/hash checks.
# These will show up in the `__mro__` before any other classes
# provided a SOMAObject base is put first:
#
# class SubType(SomeSOMAObject, MutableMapping):
# ...
#
# # sub_type_inst.__eq__ uses object.__eq__ rather than
# # MutableMapping.__eq__.

__eq__ = object.__eq__
__hash__ = object.__hash__
...

def __enter__(self) -> Self: ...

def __exit__(self, *_: Any) -> None: ...
Loading