bt2: first pass of type annotation master
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 23 Oct 2024 19:52:16 +0000 (15:52 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 4 Nov 2024 16:17:44 +0000 (11:17 -0500)
commit3a75f7405c4804a563b9399967ca7e8c0f910db6
treec0fae42f0fd331570144f28def770bddb1206939
parent8ca63428b7e205d6bff3d56bdfffb2daabdf33a6
bt2: first pass of type annotation

Do a quick pass of adding type annotations on almost everything public
in the API.  It's not perfect, for instance:

 - Because of the structure of const vs non-const objects, the typings
   claim that the non-const versions reutrn const properties, when in
   reality then return non-const properties.  For instance,
   `_StreamClass.trace_class` should return a `_TraceClass`, not a
   `_TraceClassConst`.  Some refactoring will be needed to get that
   right.

 - The typings could sometimes return a more precise type with the use
   of generics.  For instance,
   `_OptionWithUnsignedIntegerSelectorFieldClassConst.ranges()` should
   return an `_UnsignedIntegerRangeSetConst`, but it returns an
   `_IntegerRangeSetConst` right now (because the `ranges()` method is
   shared with the signed version).

 - I left out some more complex things, like the type of params (which
   is also the type of the parameter to `bt2.create_value()`).  That's a
   project for later.

Still, I think it's better than nothing, and we have to start somewhere.

Even when the return value could be inferred, I chose to specify it
explicitly.  It acts as documentation for anyone reading the code
without an analysis tool that can display the inferred value, and it
acts as validation that the functions keep returning what we want them
to return (especially if we ever run pyright or similar in the CI one
day).

Change-Id: I25999b855626ca3efb619b8cb07d267b4d8ec3ed
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/13403
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
29 files changed:
src/bindings/python/bt2/bt2/clock_class.py
src/bindings/python/bt2/bt2/clock_snapshot.py
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/connection.py
src/bindings/python/bt2/bt2/error.py
src/bindings/python/bt2/bt2/event.py
src/bindings/python/bt2/bt2/event_class.py
src/bindings/python/bt2/bt2/field.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/logging.py
src/bindings/python/bt2/bt2/message.py
src/bindings/python/bt2/bt2/message_iterator.py
src/bindings/python/bt2/bt2/mip.py
src/bindings/python/bt2/bt2/object.py
src/bindings/python/bt2/bt2/packet.py
src/bindings/python/bt2/bt2/plugin.py
src/bindings/python/bt2/bt2/port.py
src/bindings/python/bt2/bt2/py_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/trace_collection_message_iterator.py
src/bindings/python/bt2/bt2/value.py
This page took 0.029678 seconds and 4 git commands to generate.