Skip to content

SNOW-3538315: Telemetry decorators (df_api_usage etc.) erase type information on all DataFrame methods #4220

Description

@gitovska

Summary

Three telemetry decorators in snowflake/snowpark/_internal/telemetry.py are completely untyped, causing all DataFrame and RelationalGroupedDataFrame methods they wrap to return Unknown under strict type checkers (pyright, ty).

Root Cause

# telemetry.py — all three follow this pattern
def df_api_usage(func):          # no type variables
    def wrap(*args, **kwargs):   # no type variables
        ...
        return r
    return wrap

df_api_usage is the outermost decorator on DataFrame methods — applied after @publicapi — so it erases the type signature that @publicapi carefully preserves via CallableT:

@df_api_usage       # outer — strips all type information
@publicapi          # inner — uses CallableT correctly, but now overridden
def select(self, *cols) -> "DataFrame":
    ...

The same problem affects df_to_relational_group_df_api_usage and relational_group_df_api_usage.

Fix

Apply the same CallableT pattern used to fix publicapi in #2999:

from typing import TypeVar, Callable

_FuncT = TypeVar("_FuncT", bound=Callable)

def df_api_usage(func: _FuncT) -> _FuncT:
    @functools.wraps(func)
    def wrap(*args, **kwargs):
        ...
        return r
    return wrap  # type: ignore[return-value]

Apply the same fix to df_to_relational_group_df_api_usage and relational_group_df_api_usage.

Affected methods

Every public DataFrame method decorated with @df_api_usage — including select, filter, with_column, join, union, group_by, etc. — and every RelationalGroupedDataFrame aggregation method.

Related

Metadata

Metadata

Labels

status-triage_doneInitial triage done, will be further handled by the driver team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions