kRPC: Control the game using C#, C++, Java, Lua, Python...

kRPC: Control the game using C#, C++, Java, Lua, Python...

7.8k Downloads

[Python] Mode setters accept the wrong type

object-Object opened this issue ยท 0 comments

commented

The parameter type of many (probably all) mode setters (eg. Control.sas_mode, Control.speed_mode, Text.alignment) is currently whatever the type of the getter is (eg. SASMode). This results in errors from type checkers when trying to change those modes, such as in this example:

import time
import krpc

conn = krpc.connect()
vessel = conn.space_center.active_vessel
vessel.control.sas_mode = vessel.control.sas_mode.radial

This code works, but Pylance shows the following error:

Cannot assign member "sas_mode" for type "Control"
  "int" is incompatible with "SASMode"

It also breaks future autocomplete with that variable, since Pylance now thinks it's an int.

I believe this could be fixed by changing the argument type of the setters in the relevant stub files, for example, from SpaceCenter.SASMode to int:

        @sas_mode.setter
        def sas_mode(self, value):
            # type: (int) -> None
            ...

However, if possible, it would probably be better to make these types use the Enum class, since that seems to be what they're representing.

(I'm unsure if this is an issue with base kRPC or just nullprofile's fork, though I suspect the former.)