Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected keyword arguments in constructor call for inherited dataclass #3201

Closed
dwc-pixel opened this issue Oct 18, 2019 · 5 comments · Fixed by pylint-dev/astroid#1140
Closed
Labels
Bug 🪲 Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@dwc-pixel
Copy link

dwc-pixel commented Oct 18, 2019

Hello.

When handling dataclasses, if there is an init method in parent class, pylint sees this as an exception for child class arguments. The code runs without an exception but pylint complains as errors.

Steps to reproduce

1.Install python 3.7
2.Install pylint (2.3.1)
3.Run code

$ cat dataclass_test.py
import dataclasses

@dataclasses.dataclass
class MyBaseDataClass:
  arg0: str = None

  def __init__(self, arg0):
    raise NotImplementedError

@dataclasses.dataclass
class MyDataClass(MyBaseDataClass):
  arg1: float = None
  arg2: str = None

if __name__ == '__main__':
  try:
    my_base_data_class = MyBaseDataClass(arg0='base')
    print(my_base_data_class)
  except NotImplementedError:
    print('expected')

  my_data_class = MyDataClass(arg1=0, arg2='a')
  print(my_data_class)
$ pylint -E dataclass_test.py
************* Module dataclass_test
dataclass_test.py:22:18: E1123: Unexpected keyword argument 'arg1' in constructor call (unexpected-keyword-arg)
dataclass_test.py:22:18: E1123: Unexpected keyword argument 'arg2' in constructor call (unexpected-keyword-arg)
dataclass_test.py:22:18: E1120: No value for argument 'arg0' in constructor call (no-value-for-parameter)
$

Expected behavior

No error reported

pylint --version output

2.3.1

@AWhetter
Copy link
Contributor

I cannot reproduce on the latest master. Could you please confirm?

@AWhetter AWhetter added the Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine label Oct 24, 2019
@dwc-pixel
Copy link
Author

@AWhetter Didn't realize comment was a mark down. All indentations were removed. I fixed the comment on steps to reproduce. Thank you for looking into this.

@roytseng-tw
Copy link

I can reproduce the same error with

pylint 2.5.3
astroid 2.4.2
Python 3.7.6 

@Db-pckr
Copy link

Db-pckr commented Jan 26, 2021

I just found similar error in my code with:

pylint 2.6.0
astroid 2.4.2
Python 3.8.5

@AWhetter AWhetter removed the Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine label Jan 26, 2021
@thefifo
Copy link

thefifo commented Apr 15, 2021

+1

pylint 2.7.4
astroid 2.5.3
Python 3.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants