bt2: replace internal property setters with standard methods
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 12 Jun 2023 20:29:52 +0000 (16:29 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 4 Nov 2024 16:17:44 +0000 (11:17 -0500)
commitdca9db19512fa4191bc965cf8dcce885f68a8bff
tree902b70f3c0cd1ed6f23147dff055ff60c44a46b2
parent5d977114b3f2316274102ed110416549d47d13ff
bt2: replace internal property setters with standard methods

Pyright doesn't like this pattern:

    def _user_attributes(self, user_attributes):
        value = bt2_value.create_value(user_attributes)
        native_bt.field_class_variant_option_set_user_attributes(
            self._ptr, utils._check_type(value, bt2_value.MapValue)._ptr
        )

    _user_attributes = property(fset=_user_attributes)

The warning is:

    /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py
      /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:102:24 - error: Expression of type "property" cannot be assigned to declared type "(self: Self@_FieldClass, user_attributes: Unknown) -> None"
        Type "property" cannot be assigned to type "(self: Self@_FieldClass, user_attributes: Unknown) -> None" (reportGeneralTypeIssues)

What happens is that we first define a method with the
"_user_attributes", and at some later point it in the initialization,
the "_user_attributes" name in the class gets assigned a property whose
setter is the original method.  The type checker doesn't like that the
type of "_user_attributes" changes like that.

Change all instances of this pattern to just use a "_set_*" method.  I
don't think it's important for these internal APIs to be properties, in
fact I think it just makes the code hard to grep.

Change-Id: Iea3cee470f55b28ec2ec798c3a24d6e880913343
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10250
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/bindings/python/bt2/bt2/clock_class.py
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/event_class.py
src/bindings/python/bt2/bt2/field_class.py
src/bindings/python/bt2/bt2/stream.py
src/bindings/python/bt2/bt2/stream_class.py
src/bindings/python/bt2/bt2/trace.py
src/bindings/python/bt2/bt2/trace_class.py
src/bindings/python/bt2/bt2/user_attributes.py
This page took 0.025533 seconds and 4 git commands to generate.