Skip to content

Export Protocol that satisfies both this and the official implementations #2

@NickCrews

Description

@NickCrews

In ibis-project/ibis#11525, I want to make the library ibis be able to accept templatelib.Template instances.

But, I want that library code to also be able to accept the Template instances from this library. This should be fine since they have the same APIs. But, I want the typing to work. In other words, I would want something like

# ibis/some/library/module.py
from tstrings import PTemplate

def sql_value(template: PTemplate) -> ibis.Value:
    # ibis is able to handle both the official and this implementation since
    # they have the same APIs

# ===================================

# users/main.py
# in user's code they can either use the official implementation, or this backport:
import ibis
my_table = ibis.duckdb.connect("mydb.duckdb").table("my_table")
original_value = my_table.my_timestamp_column

# for users on python <3.14:
from tstrings import t
cast_value = ibis.sql_value(t("CAST({original_value} AT TIME ZONE 'America/Anchorage' AS TIMESTAMP)"))

# for users on python >=3.14
cast_value = ibis.sql_value(t"CAST({original_value} AT TIME ZONE 'America/Anchorage' AS TIMESTAMP)")

Do you have interest in supporting this use case? Does this implementation look good to you? If I submit a PR would you consider it?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions