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

Using classes "defined as generic in stubs but not at runtime" as base class triggers inherit-non-class #4697

Open
mathiasertl opened this issue Jul 10, 2021 · 1 comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@mathiasertl
Copy link

mathiasertl commented Jul 10, 2021

pylint>=2.9.0 triggers a false positive of inherit-non-class when using a class as base that was defined as a generic in a stub (or mypy plugin) but not at runtime when using the recommended workaround from mypy.

Steps to reproduce

Consider this file:

# pylint: disable=missing-module-docstring,missing-class-docstring
import typing

from django.db import models

if typing.TYPE_CHECKING:
    QuerySetBase = models.QuerySet[models.Model]
else:
    QuerySetBase = models.QuerySet


# class def will trigger: E0239: Inheriting 'QuerySetBase', which is not a class. (inherit-non-class)
class TestQuerySet(QuerySetBase):  
    pass

Current behavior

pylint>=2.9.0 triggers inherit-non-class, version 2.8.3 does not yet trigger that error.

It should be noted that a workaround is to invert the if/else statement like this:

if not typing.TYPE_CHECKING:
    QuerySetBase = models.QuerySet
else:
    QuerySetBase = models.QuerySet[models.Model]

... which will not trigger the error. Still of course, something is clearly happening that is not intended.

Expected behavior

... not trigger that error, obviously ;-)

@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 10, 2021
@Pierre-Sassoulas
Copy link
Member

To take into account when doing #3285

@Pierre-Sassoulas Pierre-Sassoulas added the Help wanted 🙏 Outside help would be appreciated, good for new contributors label Jul 10, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Hacktoberfest Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants