Convert BusState to enum when read with configparser by Gregox273 · Pull Request #1957 · hardbyte/python-can

@Gregox273

Fix bug in pcan interface where state values cannot be read from config files.

zariiii9003


self.check_api_version()

if not isinstance(state, BusState):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the wrong place for this. The config value should be converted in can.util._create_bus_config().

@zariiii9003

Could you add a test to TestBusConfig in test/test_util.py?

Greg Brooks added 5 commits

July 22, 2025 10:16

zariiii9003

)
state = can_cfg["state"]
assert isinstance(state, can.BusState)
assert state == can.BusState.PASSIVE

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: enums should be compared by identity (state is can.BusState.PASSIVE)

zariiii9003

)
state = can_cfg["state"]
assert isinstance(state, can.BusState)
assert state == expected_state

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

zariiii9003

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you