Skip to content

WIP: Explicitly cast some boolean arguments into bool#10

Open
javierggt wants to merge 1 commit intomainfrom
numpy-2
Open

WIP: Explicitly cast some boolean arguments into bool#10
javierggt wants to merge 1 commit intomainfrom
numpy-2

Conversation

@javierggt
Copy link
Contributor

@javierggt javierggt commented Jan 29, 2026

Description

This fixes some crashes when a Qt method with bool arguments takes a np.bool argument instead. This fixes the crashes I have found. It is not a general solution, and there could be other similar crashes.

Unfortunately, one error looks like this:

Traceback (most recent call last):
  File "/Users/javierg/SAO/git/aperoll/aperoll/widgets/star_plot.py", line 379, in set_visibility
    self.scene().show_fov(radius < 6)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/Users/javierg/SAO/git/aperoll/aperoll/widgets/star_plot.py", line 680, in show_fov
    self.main_fov.setVisible(show)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
TypeError: setVisible(self, visible: bool): argument 1 has unexpected type 'numpy.bool'

In this case, just because radius is an np.float, radius < 6 will be np.bool. This is then passed to FieldOfView.setVisible, which is the inherited QGraphicsItem.setVisible,and this one takes a bool argument. The difference in type causes an exception.

Considering that numpy types are everywhere, one has to:

  • override the method in derived classes so numpy types are cast in acceptable types
  • and/or make sure values passed are not numpy types anywhere

This PR does the second in a few instances. Several methods that take a bool as argument will cast it explictly before passing it to setVisible. This means littering the code with bool casts, just because a numpy type might be passed. Not nice.

Overriding the methods is not nice either. It would mean that every class that inherits from QGraphicsItem needs to have a setVisible method where the argument is cast and the QGraphicsItem.setVisible is called.

Then the question is to what other methods and types this applies. There doesn't seem to be an issue with float arguments. I do not know if this is caused by changes in numpy or by changes in the Qt python bindings.

Interface impacts

Testing

Unit tests

  • No unit tests
  • Mac
  • Linux
  • Windows

Independent check of unit tests by [REVIEWER NAME]

  • [PLATFORM]:

Functional tests

No functional testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant