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

pylint doesn't understand that typing.Dict extends dict #2420

Closed
chkno opened this issue Aug 16, 2018 · 4 comments
Closed

pylint doesn't understand that typing.Dict extends dict #2420

chkno opened this issue Aug 16, 2018 · 4 comments
Labels

Comments

@chkno
Copy link
Contributor

chkno commented Aug 16, 2018

Steps to reproduce

  1. Run pylint over this file:
"""Extend dict and Dict."""

from typing import Dict

class LittleDDict(dict):
    """An embellished dict."""

    def embellishment(self) -> None:
        """Extra functionality over dict."""
        print("I have %d items" % len(self))


class BigDDict(Dict[int, str]):
    """An embellished Dict."""

    def embellishment(self) -> None:
        """Extra functionality over Dict."""
        print("I have %d items" % len(self))


def _main() -> None:
    little_d = LittleDDict()
    little_d[3] = "three"
    little_d.setdefault(4, "four")
    little_d.embellishment()

    big_d = BigDDict()
    big_d[3] = "three"
    big_d.setdefault(4, "four")
    big_d.embellishment()

if __name__ == '__main__':
    _main()

Current behavior

$ pylint --reports=n --persistent=n extend_dict.py 
************* Module extend_dict
extend_dict.py:13:0: R0903: Too few public methods (1/2) (too-few-public-methods)
extend_dict.py:28:4: E1137: 'big_d' does not support item assignment (unsupported-assignment-operation)
extend_dict.py:29:4: E1101: Instance of 'BigDDict' has no 'setdefault' member (no-member)

-----------------------------------
Your code has been rated at 3.89/10

Expected behavior

$ pylint --reports=n --persistent=n extend_dict.py 
Your code has been rated at 10.00/10

pylint --version output

pylint 2.1.1
astroid 2.0.4
Python 3.6.5 (default, Jul  5 2018, 03:28:36) 
[GCC 8.1.0]
@PCManticore
Copy link
Contributor

Thanks for reporting an issue, I can reproduce the problem as well.

@radkujawa
Copy link

Is there a plan to to fix this bug? I can't upgrade my pylint (from ancient 2.3.1) due to multiple false positives connected to #3129, which is closed in favor of this ticket.

@matt2000
Copy link

FWIW, I've also reproduced this issue.

@hippo91
Copy link
Contributor

hippo91 commented Apr 9, 2021

@chkno @radkujawa @matt2000 i close this issue. The bug doesn't occur any more on master branch thanks to pylint-dev/astroid#921

@hippo91 hippo91 closed this as completed Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants