-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 when inheriting from a Generic class #2607
Comments
Thanks for the report! |
I think this may have been fixed. I don't reproduce it with the latest releases:
|
I can't reproduce it either. We improved the handling of the If you still experience any problems, please report back and I'll reopen it. |
I'm seeing this issue when working with Pydantic, however, I'm not sure if it's a PyLint or a Pydantic issue. I've have the classes below; import re
from pathlib import Path
from typing import Generic, Iterator, Tuple, TypeVar
from pydantic import BaseModel, ConstrainedStr, Field
from pydantic.generics import GenericModel
from pydantic.types import NegativeInt
_KT = TypeVar('_KT', str, ConstrainedStr)
_VT = TypeVar('_VT')
class RootDictModel(GenericModel, Generic[_KT, _VT]):
__root__: dict[_KT, _VT] = {}
def __getitem__(self, key: _KT) -> _VT:
return self.__root__[key]
def __iter__(self) -> Iterator[_KT]: # type: ignore
return iter(self.__root__)
def keys(self) -> list[_KT]:
return list(self.__root__.keys())
def values(self) -> list[_VT]:
return list(self.__root__.values())
def items(self) -> list[Tuple[_KT, _VT]]:
return list(self.__root__.items())
class TagKey(ConstrainedStr):
regex: re.Pattern[str] = re.compile(r'^\d*$')
class Tags(RootDictModel[TagKey, str]):
...
class Shortcut(BaseModel, extra='allow'):
id: NegativeInt = Field(alias="appid")
name: str = Field(alias="appname")
exe: str = Field(alias="exe")
dir: Path = Field(alias="StartDir")
launch: str = Field("", alias="LaunchOptions")
tags: Tags = Tags()
class Shortcuts(RootDictModel[str, Shortcut]):
...
class ShortcutsVDF(BaseModel):
shortcuts: Shortcuts Both |
Can you try using |
I've tried the pylint-pydantic plugin, which didn't help unfortunately. For now I've just disabled the pylint error in the lines affected. I have tried a couple of different things to replicate the issue without using any pydantic models but haven't been able to, suggesting it probably is an interaction issue between pydantic and pylint. |
I think opening an issue in pylint-pydantic is the thing to do at this point. We're relying on external plugin to handle libraries specificity now. |
Hi there, here's a bug in handling generics I discovered. (Somewhat related to #2568.)
When I try to inherit from a generic class (while fixing the type parameter), Pylint does not seem
to find the inherited methods. In the following example, if you remove the
[int]
part in theWorld
class definition, it works as expected.Steps to reproduce
Current behavior
Pylint reports:
test.py:17:0: R0903: Too few public methods (1/2) (too-few-public-methods)
Expected behavior
No error
pylint --version output
The text was updated successfully, but these errors were encountered: