chrysn / aiocoap

The Python CoAP library
Other
264 stars 119 forks source link

Automatically generate exception classes for all error codes #344

Closed burnpanck closed 4 months ago

chrysn commented 4 months ago

There is a competing PR #336 whose changes would boil down to spelling the types out explicitly.

This is good input (with some caveats, eg. that an assert statement can never do security critical checks because it is skipped with python -O, or in that access to locals() and type() would be superior to eval because it is not prone to code injection), but I think I we'll have to do it differently for the #336 reasons.

burnpanck commented 4 months ago

I don't have any experience with MyPy, but my gut feeling is that these tools always will have limited support to dynamic generation of entities. It may be feasible to spell out the exceptions instead of the codes and then generate the codes from the exception classes, but I guess this is probably not desirable anyway. The most conforming way would probably be to just spell out both the codes and the classes explicitly, and add a check for completeness somewhere in the tests.