-
Notifications
You must be signed in to change notification settings - Fork 133
Stub file for current module not used #1126
Comments
I thought this was #907, but I can't be sure. |
It's not #907, no, that was an ordering thing which affected a very large stub (which went away, and even on the old version I reported it for didn't persist to the end of the analysis; only observed while debugging). |
Need to check if we actually discover stubs next to the file. There is typeshed discovery and standard discovery for module stubs in https://github.com/python/mypy/wiki/Creating-Stubs-For-Python-Modules as well. |
Actually, since you are using 3.6 is there any reason you don't want to annotate in the module source code? |
@MikhailArkhipov I find the type annotation syntax very verbose and distracting and I dislike having to import from typing just for the type annotations. I prefer to write them into a special field in docstrings (in Python 2 format) where they are less distracting, and I've developed a utility that generates the stub file from these docstrings automatically. I trigger the utility whenever I save the source file so I can keep the code and the annotations close by. |
@MikhailArkhipov I've created a
And I've set:
But I couldn't make it work, still the same :( |
@MikhailArkhipov Although the mypy document you've referred to doesn't mention stub files in the same directory, the documentation on readthedocs does (the first bullet under "Creating a stub"): https://mypy.readthedocs.io/en/latest/stubs.html "Write a stub file for the library (or an arbitrary module) and store it as a .pyi file in the same directory as the library module." Am I misinterpreting something? |
We should support having the |
@jakebailey I don't know how analysis works but could this sentence from PEP-484 be relevant? "The type checker should have a configurable search path for stub files. If a stub file is found the type checker should not read the corresponding "real" module." |
We aren't a type checker by that definition per se. We provide editor features; if we were to do exactly what that line says, then you'd never get any completion, references, docstrings, etc, for a file that happens to have a stub, since we would go "hey, there's a stub" and never read the real code. Instead, we analyze both and merge the data together. |
Actually we do discover |
Environment data
VS Code version: 1.34.0
Extension version (available under the Extensions sidebar): 2019.4.12954
OS and version: Ubuntu 19.04
Python version (& distribution if applicable, e.g. Anaconda): 3.6
Type of virtual environment used: virtualenv
Problem
The type hints in the stub file for the current module aren't used for autocompletion.
I have a
foo.pyi
file as in:In the same folder, I have a
foo.py
file, which starts as:After the dot for the
s
parameter, I don't get autocompletion suggestions for thestr
class. But if I add the type hint to the parameter within the module itself, I do:The text was updated successfully, but these errors were encountered: