Skip to content

use protocols instead of optional 3rd party dependencies in public type annotationsΒ #3374

@MarcoGorelli

Description

@MarcoGorelli

This was brought up here: https://discord.com/channels/1235257048170762310/1272835922924273694/1439943293860446292

is there any particular reason to use numpdy ndarrays concrete types instead of Protocols?
This is a issue I already talked about in Polars here:
pola-rs/polars#24436

If numpy is not installed in the venv, the LSP will complain each time I'm updating narwhals/polars about unknown numpy types, and I have to manually delete them to fix it.

I think it's a valid request

Dan's comment:

Yeah I think using Protocols more would help your use-case

I've been adding some for solving the same issue in narwhals._native.py - but hadn't considered numpy.

I think the main challenge with ndarray is that we'd need to define something that only matches that - but doesn't match the 8474930 other things that based their API on it πŸ˜‚

TBH I'd be ok with accidentally matching something non-numpy, if it's not supported there'll be a runtime error anyway

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions