pandas-dev / pandas-stubs

Public type stubs for pandas
BSD 3-Clause "New" or "Revised" License
229 stars 123 forks source link

register_dataframe_accessor causes "Untyped class decorator obscures type of class; ignoring decorator" #906

Open davetapley opened 5 months ago

davetapley commented 5 months ago

Describe the bug Example from the docs causes:

Untyped class decorator obscures type of class; ignoring decoratorPylance[reportUntypedClassDecorator](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUntypedClassDecorator)

in VSCode.

To Reproduce

In VSCode:

@pd.api.extensions.register_dataframe_accessor("geo")
class GeoAccessor:
    ...

Please complete the following information:

Additional context

This fixes it, PR welcome?

from typing import Callable, TypeVar

T = TypeVar('T')  # return type

def register_dataframe_accessor(name: str) -> Callable[[T], T]: ...

See also:

twoertwein commented 5 months ago

This fixes it, PR welcome?

Yes - probably should use a more specific TypeVar, maybe DataFrameT = TypeVar("DataFrameT", bound=DataFrame).

twoertwein commented 5 months ago

I opened https://github.com/pandas-dev/pandas/pull/58339 for pandas. Feel free to open a similar PR here