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

"Literal[5]" cannot be assigned to type "ToJustInt" #420

Closed
osamimi opened this issue Jan 17, 2025 · 6 comments
Closed

"Literal[5]" cannot be assigned to type "ToJustInt" #420

osamimi opened this issue Jan 17, 2025 · 6 comments

Comments

@osamimi
Copy link

osamimi commented Jan 17, 2025

├── scipy v1.15.1
├── scipy-stubs v1.15.1.0

This call

    coeffs = scipy.signal.firls(
        numtaps=5,
        bands=np.array(scipy_bands),
        desired=np.array(scipy_desired),
        weight=np.array(scipy_weights),
        fs=1.0,
    )

produces the following:

Argument of type "Literal[5]" cannot be assigned to parameter "numtaps" of type "ToJustInt" in function "firls"
  Type "Literal[5]" cannot be assigned to type "ToJustInt"
    "Literal[5]" is incompatible with protocol "JustInt"
      "__class__" is an incompatible type
        Type "() -> type[Self@object]" cannot be assigned to type "() -> type[int]"
          Function return type "type[Self@object]" is incompatible with type "type[int]"
    "Literal[5]" is incompatible with "integer[Any]"

I don't understand why this doesn't type check?

@jorenham jorenham changed the title Literal[5]" cannot be assigned to type "ToJustInt" "Literal[5]" cannot be assigned to type "ToJustInt" Jan 18, 2025
@jorenham
Copy link
Owner

What (pyright?) version are you using?

@jorenham
Copy link
Owner

jorenham commented Jan 18, 2025

I checked with the latest pyright, basedpyright, and mypy, but I can't reproduce it.

import numpy as np
import scipy

coeffs = scipy.signal.firls(
    numtaps=5,
    bands=np.array([.0]),
    desired=np.array([.0]),
    weight=np.array([.0]),
    fs=1.0,
)
$ uv run pyright issue_420.py
0 errors, 0 warnings, 0 informations 
$ uv run basedpyright issue_420.py
0 errors, 0 warnings, 0 notes
$ uv run mypy issue_420.py
Success: no issues found in 1 source file

It would also help if you could share the particular config that you're using.

@osamimi
Copy link
Author

osamimi commented Jan 18, 2025

I was seeing this in vscode with pylance extention 2024.12.100 which seems to use pyright 1.1.390 and the setting typeCheckingMode = "standard"

Image

But I tried command-line pyright 1.1.390 and 1.1.392 and that doesn't show any errors. Not sure how to explain this...

@jorenham
Copy link
Owner

Hmm that's indeed strange... As far as I'm aware, pylance directly uses pyright 🤔

@jorenham
Copy link
Owner

Perhaps they use different typeshed versions? Because I recently fixed a bug there that was causing issues with these Just* types in pyright.

Anyway, you could try upgrading to the pre-release version of pylance, and see if that helps.

@jorenham
Copy link
Owner

I just tried with Pylance 2024.12.100 in standard more, but I'm still not able to reproduce it. Did you try reinstalling Pylance?

@jorenham jorenham closed this as not planned Won't fix, can't repro, duplicate, stale Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants