gnuradio icon indicating copy to clipboard operation
gnuradio copied to clipboard

runtime: Use ABC's in tag_utils

Open souponaroom opened this issue 1 year ago • 1 comments

Description

Currently, tag_utils detects if an argument in python is an integer/list/whatever by checking its type. This can lead to hard to track bugs if e.g. the programmer attempts to use a numpy np.int_ or an ndarray. These types can be supported by having isinstance check for an abstract base class.

Which blocks/areas does this affect?

None

Testing Done

This change is trivial so I have not added a unit test, but all old tests still pass. If I should create a unit test, let me know. An older codebase I was reformatting was not working due to np.ndarray and numpy int usage, and now it works with this change, so the change seems to do exactly what it ought to do.

Checklist

souponaroom avatar Aug 03 '24 05:08 souponaroom

Looking back at my request, I have just realized that it's entirely possible for a collections.abc.Collection to not support __getitem__, which is required by the code.

The most broad abc that adequately defines what's required in line 72 is a Sequence, but that type is too restrictive, as ndarrays are not sequences.

I still think that detecting "close-ish" types for arguments should be supported, or at least not silently fail, but I'll need to check the Python features to see how to do so correctly.

souponaroom avatar Aug 11 '24 20:08 souponaroom