Skip to content

Improve Liskov diagnostics to say *why* a method override is incompatible #1644

@tronical

Description

@tronical

Summary

uvx ty@0.0.1a28 check yields:

error[invalid-method-override]: Invalid override of method `set_row_data`
  --> slint/models.py:90:9
   |
88 |         return self.list[row]
89 |
90 |     def set_row_data(self, row: int, data: T) -> None:
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Definition is incompatible with `Model.set_row_data`
91 |         self.list[row] = data
92 |         super().notify_row_changed(row)
   |
  ::: slint/models.py:36:9
   |
34 |         return ModelIterator(self)
35 |
36 |     def set_row_data(self, row: int, value: T) -> None:
   |         ---------------------------------------------- `Model.set_row_data` defined here
37 |         """Call this method on mutable models to change the data for the given row.
38 |         The UI will also call this method when modifying a model's data.
   |
info: This violates the Liskov Substitution Principle
info: rule `invalid-method-override` is enabled by default

Found 1 diagnostic

The signatures are identical, so I'm not sure what's wrong here :)

For reference (with code removed):

class Model[T](native.PyModelBase, Iterable[T]):
   
    def set_row_data(self, row: int, value: T) -> None:
   
class ListModel[T](Model[T]):
  
    def set_row_data(self, row: int, data: T) -> None:
        ...

Version

0.0.1a28

Metadata

Metadata

Assignees

Labels

diagnosticsRelated to reporting of diagnostics.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions