pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Module is not callable

Open tiagovla opened this issue 3 years ago • 1 comments

import matplotlib.pyplot as plt
import numpy as np

x, y = np.meshgrid(np.linspace(-1, 1, 10), np.linspace(-1, 1, 10))
x, y = x.ravel(), y.ravel()
fig, ax = plt.subplots(constrained_layout=True)
ax.tripcolor(x, y, np.sin(x) + np.cos(y))
plt.show()

This shows Module is not callable at ax.tripcolor.

Version: v2022.9.11 Python: 3.10.5 OS: Linux Arch

Also: https://github.com/microsoft/python-type-stubs/issues/226

tiagovla avatar Sep 09 '22 03:09 tiagovla

workaround. update you stub to point to the function of the same name. image

bschnurr avatar Sep 09 '22 17:09 bschnurr

I have stumbled on a similar problem. I guess it may be the same bug, so I report it here. If not, please let me know.

from kedro.pipeline import Pipeline, pipeline

def create_pipeline(**kwargs) -> Pipeline:
    return pipeline([])

Pylance threw Module is not callable at the line return pipeline([]) because it confused the function pipeline with the module pipeline. However, the error disappeared when I modified my code as follows:

from kedro.pipeline import Pipeline
from kedro.pipeline.modular_pipeline import pipeline

def create_pipeline(**kwargs) -> Pipeline:
    return pipeline([])

lamhm avatar Jan 12 '23 03:01 lamhm

Given that « matplotlib 3.8 will ship with typing stubs » (https://github.com/matplotlib/matplotlib/issues/24701#issuecomment-1530126439), you can try the in-development version using pip install git+https://github.com/matplotlib/matplotlib.git#egg=matplotlib.

It should work as-is with pyright and mypy, but for Pylance you'll have to remove the bundled stubs everytime you update the extension. it can be found at: %HOMEPATH%\.vscode\extensions\ms-python.vscode-pylance-<VERSION>\dist\bundled\stubs\matplotlib (where <VERSION> is your current Pylance version).

If the issue persists, you can raise it upstream.

Avasam avatar Jun 13 '23 05:06 Avasam

I am still seeing this or a similar issue. Should I make a new issues?

image

Here both the module and the function are called acorn.

# my_package/__init__.py
from .acorn import acorn
from .banana import Banana

judfs avatar Dec 05 '23 19:12 judfs

@judfs, see https://github.com/microsoft/pyright/issues/3131. This is by design. If you think your scenario is somehow different from than one, please open a new issue.

debonte avatar Dec 05 '23 22:12 debonte