Comments (8)
I wonder if it would be better to be able to specify additional stubs dirs as a command line argument or something...
from mypy.
You can specify an additional module path (for looking up stubs or any modules) by using the MYPYPATH environment variable. The implicit 'stubs' directory would just be a convenience.
from mypy.
As we now have an alternative extension for stubs, this is no longer as urgent: #345
from mypy.
The .pyi extension seems to address this issue, so closing this now.
from mypy.
Hi,
This might be a stupid question, but I have tried the both methods to use a local stub: putting the pyi file in the same directory as the py file to run and exporting MYPMPATH to a stub directory and put the pyi file there. I named both pyi file the same name as the py file except for the extension. However, both situations does not throw an error when I run a test program with the incorrect typing hint.
Is there some new way to use the new local stub or I was just stupid and misunderstand the instruction?
from mypy.
from mypy.
So as a follow up I also can't seem to sort out the problems with local stub files.
I have the following project structure:
stub-typing/
├── stubtyping/
│ ├── __init__.py
│ ├── main.py
│ └── main.pyi
└── venv/
main.py
has the following content:
def add(a, b):
return a + b
add(1, 2)
add('a', 'b')
and main.pyi
has:
def add(a: int, b: int) -> int: ...
When MYPYPATH
is unset and I execute mypy stubtyping/
I have a blank output instead of the expected:
main.py:6: error: Argument 1 to "add" has incompatible type "str"; expected "int"
main.py:6: error: Argument 2 to "add" has incompatible type "str"; expected "int"
I also tried to setMYPYPATH
to stubtyping/
but I still get the same results.
What am I missing?
from mypy.
Next time please use the Gitter channel (see project README).
The answer is that mypy ignores main.py
because it finds main.pyi
in the same directory. This is by design. If you want type annotations, put then in main.py
and get rid of main.pyi
.
from mypy.
Related Issues (20)
- False positive on return type HOT 2
- Can JSON format output and command line parameter options for -- disable-error-code all be supported?
- [stubgen] infer_sig_from_docstring fails with python3.12 inline generic HOT 2
- Wrong type inference with "yield from" from an Iterator class HOT 1
- Cannot infer type argument with TypeVarTuple and Callback protocol HOT 4
- `OverflowError`s and `MemoryError`s in helper functions HOT 4
- using a decorator on an overloaded function where the decorator uses `Concatenate` causes false positive "Overloaded function implementation does not accept all possible arguments" error HOT 3
- Direction of comparison operator in error message does not depend on direction in code
- functools.partial false negative with higher order functions
- Unexpected `[no-redef]` errors for plugin-generated class replacement attributes if `[name-defined]` occurs in the same module
- (🐞) `--update-data` removes escapes
- Confusing description for --no-namespace-packages HOT 2
- (🐞) `type[T]` can't be assigned to `Protocol` with `__name__`
- Dataclasses should define `__replace__` in 3.13
- Error suddenly appears from Python 3.10 and above. HOT 2
- Recursion Error for Protocols with Self HOT 3
- Class format of TypedDict does not produce proper coverage
- (🐞) incompatible `Callable`s are incorrectly joined into `builtins.function`
- (🐞) overlapping `Callable`s are incorrectly joined into `builtins.function`
- Behaviour of typing overloads in `Protocol`and their implementations? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mypy.