aai-institute / lakefs-spec

An fsspec implementation for the lakeFS project.
http://lakefs-spec.org/
Apache License 2.0
37 stars 4 forks source link

Investigate ways of simplifying transaction `Placeholder` class #207

Closed Maciej818 closed 6 months ago

Maciej818 commented 6 months ago

Motivation

Simplify working with the Placeholder objects used by the transaction feature.

Requested solution

We should investigate how to simplify working with the Placeholder objects used by the transaction feature (e.g., removing the need to call placeholder.unwrap() to obtain the underlying object).

Proposed implementation approach

@AdrianoKF has a quick prototype based on the wrapt package, which might serve as a starting point:

from dataclasses import dataclass
from typing import Generic, TypeVar

import wrapt

T = TypeVar("T")

@dataclass
class Data:
    message: str

class Future(Generic[T], Data, wrapt.ObjectProxy):
    @property
    def is_filled(self) -> bool:
        return self.__wrapped__ is not None

a = Data("hello")
wrapped = Future(a)
print(a, wrapped)
print(a.message, wrapped.message)
print(wrapped.is_filled)
print(a is wrapped)

print("-" * 80)

empty_wrapper = Future[Data](None)
print(empty_wrapper.is_filled)

Resources:

wrapt — wrapt 1.16.0 documentation

Additional context

No response

Related GitHub issue(s)

No response

Acceptance Criteria (mandatory to start implementation)

Definition of Done (mandatory to close an issue as completed)