Skip to content

[0.53.0 regression] Problem when using class definition on top of a ClassVar #2543

@sobolevn

Description

@sobolevn

I have a base class which defines a ClassVar:

from typing import ClassVar

class Endpoint: ...

class Controller:
     endpoint_cls: ClassVar[type[Endpoint]] = Endpoint

Later I have a subclass of a Controller which is defined like so:

class MyController(Controller):
     class endpoint_cls(Endpoint): ...

For this code pyrefly raises:

 poetry run pyrefly check
 INFO Checking project configured at `/home/runner/work/django-modern-rest/django-modern-rest/pyproject.toml`
ERROR Class member `SSEController.endpoint_cls` overrides parent class `Controller` in an inconsistent manner [bad-override]
   --> dmr/sse/builder.py:284:15
    |
284 |         class endpoint_cls(Endpoint):  # noqa: N801, WPS431
    |               ^^^^^^^^^^^^
    |
  `SSEController.endpoint_cls` is not a ClassVar, but `Controller.endpoint_cls` is
 INFO 1 error (68 suppressed)

It looks like a false-positive to be. Because class endpoint_cls definition is made on the class level, not instance level.

CI link: https://github.com/wemake-services/django-modern-rest/actions/runs/22378967600/job/64775321370?pr=562
Original source: https://github.com/wemake-services/django-modern-rest/blob/91b1be5bd57618223aec149963cd3ce2f3460d8c/dmr/sse/builder.py#L284-L285

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions