The pytype team has internally discussed the idea of supporting "stub overlays". Our idea was to do this at a module level, so that definitions would be recursively merged without any explicit annotations; in this instance you would have a file named `pandas_overlay.pyi` and define `class DataFrame` in it, which would modify `pandas.DataFrame` when imported.

martin

On Wed, Sep 14, 2022 at 7:49 AM Irv Lustig <irv@princeton.com> wrote:
I'm the leader of the pandas-stubs project.  In pandas, users can extend the library by creating their own accessor via `@pd.api.extensions.register_dataframe_accessor` (see https://pandas.pydata.org/docs/reference/api/pandas.api.extensions.register_dataframe_accessor.html).  So for a `DataFrame`, if you do `@pd.api.extensions.register_dataframe_accessor("xyz")`, you now have `DataFrame.xyz` returning the class you annotated.

Now suppose you want to create a stub for your new accessor, that would extend the existing pandas-stubs.  AFAIK, there isn't a way to do something like this in a stub:
```
from pandas import DataFrame
@typing.extend
class DataFrame:
    def xyz(self) -> MyXyzClass: ...
```
The idea here is that there is a class (in this case, `DataFrame`) that already has stubs, and you want to add a method to it.

Has this idea been discussed anywhere?
_______________________________________________
Typing-sig mailing list -- typing-sig@python.org
To unsubscribe send an email to typing-sig-leave@python.org
https://mail.python.org/mailman3/lists/typing-sig.python.org/
Member address: mdemello@google.com