Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Class __init__ "Too few arguments" should be a better error message #9340

Description

@indigoviolet

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:

  • Are you reporting a bug, or opening a feature request?

Feature request

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
class Foo:
    def __init__(self, bar: int):
        pass


f = Foo()
  • What is the actual behavior/output?
➜ 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)
  • What is the behavior/output you expect?

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.

  • What are the versions of mypy and Python you are using?

0.782, 3.8.1

  • Do you see the same issue after installing mypy from Git master?

I have not tested this.

  • What are the mypy flags you are using? (For example --strict-optional)

--pretty

  • If mypy crashed with a traceback, please paste
    the full traceback below.

(You can freely edit this text, please remove all the lines
you believe are unnecessary.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions