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:
This page took 0.027889 seconds and 4 git commands to generate.