Argument of Enum type only Python -
i have simple piece of python code, have number of enums defined this:
import sys time import sleep enum import enum class bw(enum): lte1p4 = 0 lte3 = 1 lte5 = 2 lte10 = 3 lte15 = 4 lte20 = 5
i want member functions of class accept enum type argument , script should not run otherwise, here main class:
class breithorn: def __init__(self): self.rx_settings = {} self.tx_settings = {} def rx_bw(self,bw): self.rx_settings['bw'] = bw
i want member function accept these kind of calls:
breithorn.rx_bw(bw.lte5)
and reject (syntax error) these kind of calls:
breithorn.rx_bw(44)
can explain how this?
you cannot make syntax error, discovered in parsing process, @ point parser has no idea symbols bound to.
you can check type @ runtime in function , raise exception.
python uses duck typing, discover these kind of problems need unit or integration tests.
Comments
Post a Comment