Asserts in Python code
Asserts in Python code
As prl recently pointed out, there are a number of instances in the enigma2 (and plugin) Python code where "assert" is used to catch code errors. Unfortunately, these asserts have no effect, since the code is always compiled with optimisation turned on.
This is a real shame, because coding errors are not being caught in either development or production use. It would be good to convert some of these asserts into their unconditional "raise AssertionError" equivalent. There are no shortcuts here, since assignments to __debug__ are illegal.
Of course, doing this has the potential to introduce many places where code that used to silently misbehave will now crash and complain. This is both good and bad. Good for developers, because problem areas will be identified easily, bad for end users, because instead of unexpected behaviour, they may get a crash.
Opinions, suggestions, feedback?
This is a real shame, because coding errors are not being caught in either development or production use. It would be good to convert some of these asserts into their unconditional "raise AssertionError" equivalent. There are no shortcuts here, since assignments to __debug__ are illegal.
Of course, doing this has the potential to introduce many places where code that used to silently misbehave will now crash and complain. This is both good and bad. Good for developers, because problem areas will be identified easily, bad for end users, because instead of unexpected behaviour, they may get a crash.
Opinions, suggestions, feedback?
-
- Wizard God
- Posts: 32714
- Joined: Tue Sep 04, 2007 13:49
- Location: Canberra; Black Mountain Tower transmitters
Re: Asserts in Python code
I think it's probably worth doing.
There are about 70 assert statements in about 35 files in the easy-ui-4 Python code.
I think it would be best to do it in stages, a few files at a time.
There are about 70 assert statements in about 35 files in the easy-ui-4 Python code.
I think it would be best to do it in stages, a few files at a time.
Peter
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV
Re: Asserts in Python code
Are any of them going to have a time-critical impact? More incentive to treat them on a case-by-case basis.
Logitech Harmony Ultimate+Elite RCs
Beyonwiz T2/3/U4/V2, DP-S1 PVRs
Denon AVR-X3400h, LG OLED65C7T TV
QNAP TS-410 NAS, Centos File Server (Hosted under KVM)
Ubiquiti UniFi Managed LAN/WLAN, Draytek Vigor130/Asus RT-AC86U Internet
Pixel 4,5&6, iPad 3 Mobile Devices
Beyonwiz T2/3/U4/V2, DP-S1 PVRs
Denon AVR-X3400h, LG OLED65C7T TV
QNAP TS-410 NAS, Centos File Server (Hosted under KVM)
Ubiquiti UniFi Managed LAN/WLAN, Draytek Vigor130/Asus RT-AC86U Internet
Pixel 4,5&6, iPad 3 Mobile Devices
-
- Wizard God
- Posts: 32714
- Joined: Tue Sep 04, 2007 13:49
- Location: Canberra; Black Mountain Tower transmitters
Re: Asserts in Python code
I had a quick look at all the "assert" lines (without looking at their context), and I didn't see any that looked as though they contained an expensive test. But of course, if the cost of the test is a significant part of the cost of a loop iteration in a loop that iterates many times, you'd need to think a bit about it.MrQuade wrote:Are any of them going to have a time-critical impact? More incentive to treat them on a case-by-case basis.
Peter
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV
T4 HDMI
U4, T4, T3, T2, V2 test/development machines
Sony BDV-9200W HT system
LG OLED55C9PTA 55" OLED TV
Re: Asserts in Python code
Hi,
I also think it is worth the effort to force the errors to the surface so that they can be properly stomped out. Incorrectly handled error conditions are probably going to manifest as other errors and issues that will be much harder to profile and identify. (Anyone remember the issues about arrow buttons that stopped working etc.)
Are there sufficient resources available to fix the code as faults are found? Will code updates be available as online updates (rather than full USB reloads) for fast tracked updates and testing?
I would suggest that this only be done as a *special* beta series that is not in the usual place and not encouraged for regular users. Only users who are prepared to run unstable firmware and will contribute appropriate failure reports should be encouraged to run this special series of firmware.
Regards,
Ian.
I also think it is worth the effort to force the errors to the surface so that they can be properly stomped out. Incorrectly handled error conditions are probably going to manifest as other errors and issues that will be much harder to profile and identify. (Anyone remember the issues about arrow buttons that stopped working etc.)
Are there sufficient resources available to fix the code as faults are found? Will code updates be available as online updates (rather than full USB reloads) for fast tracked updates and testing?
I would suggest that this only be done as a *special* beta series that is not in the usual place and not encouraged for regular users. Only users who are prepared to run unstable firmware and will contribute appropriate failure reports should be encouraged to run this special series of firmware.
Regards,
Ian.
Re: Asserts in Python code
If the changes are rolled out gradually in stages, I would be happy with them being rolled out in the regular beta feed. I think we have been quite spoiled by the beta stability to date, a credit to all involved
If any showstopper bugs are found, then the asserts can just be reinstated and pushed out as an interim update, while the underlying bug is found and squashed.
If any showstopper bugs are found, then the asserts can just be reinstated and pushed out as an interim update, while the underlying bug is found and squashed.
Logitech Harmony Ultimate+Elite RCs
Beyonwiz T2/3/U4/V2, DP-S1 PVRs
Denon AVR-X3400h, LG OLED65C7T TV
QNAP TS-410 NAS, Centos File Server (Hosted under KVM)
Ubiquiti UniFi Managed LAN/WLAN, Draytek Vigor130/Asus RT-AC86U Internet
Pixel 4,5&6, iPad 3 Mobile Devices
Beyonwiz T2/3/U4/V2, DP-S1 PVRs
Denon AVR-X3400h, LG OLED65C7T TV
QNAP TS-410 NAS, Centos File Server (Hosted under KVM)
Ubiquiti UniFi Managed LAN/WLAN, Draytek Vigor130/Asus RT-AC86U Internet
Pixel 4,5&6, iPad 3 Mobile Devices
Re: Asserts in Python code
My intent would be to use the normal beta cycle to get a fairly wide exposure. Probably do this in several passes, allowing for a bit of real-world use at each stage. If errors are raised, the modus operandi would be to investigate and fix the problem, instead of rolling back. I'd probably do this mainly as online updates in order to avoid the overhead of pushing out full USB images.