Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type checking fails on any symbol exported by pedalboard #333

Open
mttbernardini opened this issue May 22, 2024 · 2 comments
Open

Type checking fails on any symbol exported by pedalboard #333

mttbernardini opened this issue May 22, 2024 · 2 comments

Comments

@mttbernardini
Copy link

I created a minimum failing example here with a workflow matrix that tests using mypy, pyright, pyre and pytype. Of all the type checkers, only pyright is able to properly evaluate the snippet without raising errors and properly infer the type of gain:

import pedalboard

# mypy: Name "pedalboard.Plugin" is not defined [name-defined]
# pyre: Undefined or invalid type [11]: Annotation `pedalboard.Plugin` is not defined as a type.
gain: pedalboard.Plugin

# mypy: Module has no attribute "Gain" [attr-defined]
# pyre: Undefined attribute [16]: Module `pedalboard` has no attribute `Gain`.
gain = pedalboard.Gain()

# mypy, pyre, pytype: Revealed type is "Any"
# pyright: Type of "gain" is "Gain"
reveal_type(gain)

Versions:

  • pedalboard == 0.9.6
  • mypy == 1.10.0
  • pyright == 1.1.363
  • pyre-check == 0.9.21
  • pytype == 2024.4.11
@hendriks73
Copy link

hendriks73 commented Oct 31, 2024

For mypy, I guess you would first have to run stubgen to get better type-checking. Unfortunately the generated stubs also have quite a few errors in them...

So what's missing, I guess, is some manually-checked/-authored pedalboard-stubs package.

After some more digging, I realized that the stubs are already there of course.
But they are only picked up by mypy when using import pedalboard_native instead of import pedalboard.

Is there any reason not to use pedalboard_native?
Or the other way around: Is there a way to tell mypy that what applies for pedalboard_native also applies to pedalboard?

@mttbernardini
Copy link
Author

mttbernardini commented Oct 31, 2024

Or the other way around: Is there a way to tell mypy that what applies for pedalboard_native also applies to pedalboard?

According to PEP-561, Python packages containing stubs (i.e. only .pyi files) should use the -stubs suffix, quoting the PEP:

The name of the stub package MUST follow the scheme foopkg-stubs for type stubs for the package named foopkg

So I suppose pedalboard_native should be named pedalboard-stubs instead, for typing information to be properly picked by mypy & co, if that's the package meant to be stubs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants