caikit icon indicating copy to clipboard operation
caikit copied to clipboard

dataobjects should not hide static typing via the decorated class

Open sboagibm opened this issue 2 years ago • 0 comments

Describe the bug

For the @dataobject decorator, you loose the tool-time ability to have typing on the dataobject class, because the way the decorator is typed, with Type[DataBase] hides the original class type.

So, in PyCharm:

  1. Trying to access instance variables by dot addressing will show as errors, and won't allow code completion. image

  2. The constructor is missing and apparently PyCharm is not smart enough to know the dataobject is a dataclass. With a dataclass, you do get the constructor hints: image

Platform

Please provide details about the environment you are using, including the following:

  • Interpreter version: Python 3.11.4
  • Library version: main ee0fbf4434ae84eb72d7eb79dfd8a006c28d6b7f
  • PyCharm 2023.1.3 (Professional Edition) Build #PY-231.9161.41, built on June 20, 2023 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 13.4 Memory: 12000M Cores: 10

Sample Code

from typing import List

from caikit.core import dataobject, DataObjectBase


@dataobject(package="caikit_data_model.wdu")
class TextLine(DataObjectBase):
    bbox: List[float]  # Coordinates
    text_line_id: int


def test_text_line_to_proto_and_back():
    msg = TextLine(bbox=[22.0, 45.0, 324.0, 897.0], text_line_id=934)

    assert msg.bbox == [22.0, 45.0, 324.0, 897.0]
    assert msg.text_line_id == 934

Shows up in the ID as: image

Expected behavior

Trying to access instance variables by dot addressing won't show as errors, and will show code completion options.

Observed behavior

Per above screen dumps.

Additional context

Slack discussion: https://ibm-analytics.slack.com/archives/C04K2B8QUG7/p1687233366250279

sboagibm avatar Jun 23 '23 16:06 sboagibm