python: make all _get_ref/_put_ref proper static methods
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 8 Jun 2023 14:57:48 +0000 (10:57 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 8 Jun 2023 19:13:01 +0000 (15:13 -0400)
commit9dee90bdad3dac00a1caff5c9a1e58fb284ee19d
tree32e3f21eaf0fc5f8709d6c0e9b43354df061ee7f
parente57959f4c84bbec191771a1598e270bfc19b6c7f
python: make all _get_ref/_put_ref proper static methods

The pyright static type checker doesn't like for these methods in
_SharedObject:

    @staticmethod
    def _get_ref(ptr):
        raise NotImplementedError

    @staticmethod
    def _put_ref(ptr):
        raise NotImplementedError

... to be overriden by assignment like this:

    _get_ref = staticmethod(native_bt.field_class_get_ref)
    _put_ref = staticmethod(native_bt.field_class_put_ref)

The warnings it gives are:

    /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py

      /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:48:16 - error: Expression of type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to declared type "(ptr: Unknown) -> Unknown"
        Type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to type "(ptr: Unknown) -> Unknown"
          Parameter name mismatch: "ptr" versus "field_class" (reportGeneralTypeIssues)

      /home/smarchi/src/babeltrace/src/bindings/python/bt2/bt2/field_class.py:49:16 - error: Expression of type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to declared type "(ptr: Unknown) -> Unknown"
        Type "staticmethod[(field_class: Unknown), Unknown]" cannot be assigned to type "(ptr: Unknown) -> Unknown"
          Parameter name mismatch: "ptr" versus "field_class" (reportGeneralTypeIssues)

So, it's just the parameter name that it doesn't like.  The obvious
solution would be to rename the `ptr` parameters of
_SharedObject._{get,put}_ref to `field_class`, in _SharedObject, to
match the names in native_bt.py.  However, I don't want us to be tied to
the names in native_bt.py (which originally come from the C header
files), as in Python we often want to use `ptr` in the name to
differentiate the SWIG wrapper around the pointer and the higher-level.
Another solution might be to use SWIG code to rename function parameters
in the SWIG-generated code, but I'm not so well-versed in SWIG, I
couldn't find how to do that.

So, I propose to just use the standard syntax for methods instead, the
type checker seems to be happy with that.

Change-Id: Ife5ad007aea4fb315d3ff4f8da67c48f4bf3e96d
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10240
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
19 files changed:
src/bindings/python/bt2/bt2/clock_class.py
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/connection.py
src/bindings/python/bt2/bt2/event_class.py
src/bindings/python/bt2/bt2/field_class.py
src/bindings/python/bt2/bt2/field_path.py
src/bindings/python/bt2/bt2/graph.py
src/bindings/python/bt2/bt2/integer_range_set.py
src/bindings/python/bt2/bt2/interrupter.py
src/bindings/python/bt2/bt2/message.py
src/bindings/python/bt2/bt2/message_iterator.py
src/bindings/python/bt2/bt2/packet.py
src/bindings/python/bt2/bt2/plugin.py
src/bindings/python/bt2/bt2/query_executor.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/value.py
This page took 0.026415 seconds and 4 git commands to generate.