Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues
Please provide more information to help us understand the issue:
Feature request
class Foo:
def __init__(self, bar: int):
pass
f = Foo()
➜ python test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
f = Foo()
TypeError: __init__() missing 1 required positional argument: 'bar'
~ via ⬢ 13.8.0 via 🐍 3.8.1
➜ mypy --pretty test.py
test.py:6: error: Too few arguments for "Foo"
f = Foo()
^
Found 1 error in 1 file (checked 1 source file)
mypy should say which arguments are missing, like Python does. This was fixed for functions in #505, but it doesn't seem to work for class __init__.
0.782, 3.8.1
I have not tested this.
--pretty
(You can freely edit this text, please remove all the lines
you believe are unnecessary.)
Hi,
This would be my first time contributing to this repo. Can I take this up ?
Sure, give it a try. Read CONTRIBUTING.md to get started.
I took a look at this issue recently. The problem is reproduced not only on "init" but for empty function as well.
With next samples:
a = 2
a.__pow__()
class Foo:
def __init__(self, bar: int):
pass
c = Foo()
def foo(baz: int, bas: int):
pass
foo()
mypy returns:
(mypy) ➜ mypy git:(master) ✗ mypy samples-9340.py
samples-9340.py:2: error: Too few arguments for "__pow__" of "int"
samples-9340.py:10: error: Too few arguments for "Foo"
samples-9340.py:17: error: Too few arguments for "foo"
Found 3 errors in 1 file (checked 1 source file)
As I understand, the function doesn't enter in that main "if" because argument_names is [], subsequently, the length is less then 1, "all" returns False as well. My proposal https://github.com/Shkurupii/mypy/commit/0c759bcdb5c569242aeb4a56e20d7743fcf5a520 is to leave a check only for argument_names is None only. The mypy in this way returns errors similar to the python interpreter.
Basically, the idea is to treat everything in "Missing positional argument" way no matter zero arguments passed or more.
(mypy) ➜ mypy git:(issue-9340) ✗ mypy samples-9340.py
samples-9340.py:2: error: Missing positional argument
samples-9340.py:10: error: Missing positional argument "bar" in call to "Foo"
samples-9340.py:17: error: Missing positional arguments "baz", "bas" in call to "foo"
Found 3 errors in 1 file (checked 1 source file)
But in that case, it requires a lot of refactoring over tests, 197 tests are broken.
@gvanrossum what do you think? give me a few words of advice
I'm sorry, I don't have time right now.
No problem.
@JukkaL maybe you suggest smth.
@ilevkivskyi, maybe you can suggest
Maybe try a simpler issue rather than spamming all the devs.
Most helpful comment
Maybe try a simpler issue rather than spamming all the devs.