Skip to content

Class loses type due to bindable_dataclass decorator (in VS Code) #5798

@platinops

Description

@platinops

First Check

  • I added a very descriptive title here.
  • This is not a security issue (those should be reported via the security advisory instead).
  • This is not a Q&A. I am sure something is wrong with NiceGUI or its documentation.
  • I used the GitHub search to find a similar issue and came up empty.

Example Code

from dataclasses import dataclass
from nicegui.binding import bindable_dataclass


class Demo:
    value: int


@dataclass
class DemoDC:
    value: int


@bindable_dataclass
class DemoNG:
    value: int


Demo().value = 1
DemoDC().value = 1
DemoNG().value = 1

Description

When I add this code to VS Code with Python extension, the last line does not autocomplete ".value".

Looks like the type checker cannot determine the type of the DemoNG() instance.

See also below screenshot:

Image

NiceGUI Version

3.7.1

Python Version

3.11.14

Browser

Firefox

Operating System

Windows

Additional Context

Tested in VS Code on both Win11 and Red Hat Linux.

It works fine if I remove the return type of nicegui.binding.bindable_dataclass in this line:

**kwargs: Any) -> type[DataclassInstance] | IdentityFunction:

Though I guess that return type was placed there for a reason :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureType/scope: New or intentionally changed behaviorin progressStatus: Someone is working on it

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions