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

False positive too-few-public-methods for TypedDict in Python 3.9 #4180

Closed
wshanks opened this issue Mar 3, 2021 · 2 comments · Fixed by #4191
Closed

False positive too-few-public-methods for TypedDict in Python 3.9 #4180

wshanks opened this issue Mar 3, 2021 · 2 comments · Fixed by #4191
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@wshanks
Copy link

wshanks commented Mar 3, 2021

This is a follow up to #1927, #2607, and #4072. In Python 3.9, TypedDict was changed from a class to a function with metaclass magic. This change caused worse problems initially (fixed by #4072), but now pylint gives a warning about too few public methods when subclassing TypedDict to create a new type as suggested in the documentation (https://docs.python.org/3/library/typing.html#typing.TypedDict). A work around is to use one of the alternate TypedDict syntax forms in which TypedDict is used as a function instead of a class.

Steps to reproduce

Given a file a.py:

"Demo"
import typing


class Coordinate(typing.TypedDict):
    "This is my type"
    x: float
    y: float

Current behavior

Result of pylint a.py:

************* Module test
test.py:5:0: R0903: Too few public methods (0/2) (too-few-public-methods)

------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 7.50/10, +0.00)

Expected behavior

No warnings.

pylint --version output

Result of pylint --version output:

pylint 2.7.2                                                                                  
astroid 2.5.1                                                                                 
Python 3.9.2
@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels Mar 3, 2021
@cdce8p
Copy link
Member

cdce8p commented Mar 4, 2021

Yeah, with pylint-dev/astroid#915 TypedDicts are now inferred as classes and thus all default class checks do apply. It might indeed make sense to disable too-few-public-methods if the class inherits from TypedDict.

@cdce8p
Copy link
Member

cdce8p commented Mar 5, 2021

Opened #4191 to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants