I entered the command:
$ mypy mypycode.py
Then I run the following code in mypycode.py:
from mypyc.build import mypycify
from setuptools import setup
from timeit import timeit
import math
setup(
name="mypycode",
package=["mypycode"],
ext_module=mypycify(["mypycode.py"])
)
print("doing something that I want to optimize with mypy")
But it threw an error:
mypycode.py:1: error: Skipping analyzing "mypyc.build": module is installed, but missing library stubs or py.typed marker [import-untyped]
mypycode.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
mypycode.py:2: error: Skipping analyzing "setuptools": module is installed, but missing library stubs or py.typed marker [import-untyped]
People are only talking how to ignore the problem, but I want to actually annotate the module. I just want to see a concrete example of a program that works. I mean, what exactly do I need to do? I don’t know how to annotate the type of a module. The given link doesn’t contain any examples that works on my computer. Are there something to do with file path? If so, please let me know how to find the file path. Thanks!
Note: I use the setup things based on this YouTube video 3:38, I am not sure if it is the correct way to enable mypy.
mypy's import-untyped
errors are normally due to one of the following:
py.typed
file;<library name>-stubs
package available for installation.See Distributing type information for more info.
For the snippet in the question, both already have solutions:
py.typed
file in master, so this error should no longer occur in the next published version of mypy;setuptools-stubs
is distributed via the types-setuptools
library, which you can install via pip install types-setuptools
. This package is maintained by the typeshed project.More generally, mypy's latest release (1.14) now contains an opt-in option to analyse packages which didn't comply with the standardised way of distributing typing information, so this error should no longer be visible if you activate this option. From the release notes:
... you can now use the
--follow-untyped-imports
flag or set thefollow-untyped-imports
config file option toTrue
.
Here's a minimal configuration file which should suppress the errors coming from mypyc:
[mypy]
[mypy-mypyc.*]
follow_untyped_imports = True
# Before `follow_untyped_imports = True`: Errors
# After `follow_untyped_imports = True`: No errors
import mypyc.build
# Before `follow_untyped_imports = True`: Revealed type is "Any"
# After `follow_untyped_imports = True`: Shows actual signature
reveal_type(mypyc.build.mypycify)