Clean up import from comm.serial
Hi,
I did some code review recently.
I found that code and i would like to know why it is so complex for something which can be done is mostly a single line.
# Export serial globals to the current module
globals().update(
{
name: getattr(serial, name)
for name in [
"EIGHTBITS",
"FIVEBITS",
"PARITY_EVEN",
"PARITY_MARK",
"PARITY_NONE",
"PARITY_ODD",
"PARITY_SPACE",
"SEVENBITS",
"SIXBITS",
"STOPBITS_ONE",
"STOPBITS_ONE_POINT_FIVE",
"STOPBITS_TWO",
]
}
)
try:
from serial import rfc2217
from serial import serialutil
except ImportError:
pass
else:
# import all rfc2217 protol keys in this module
key_match = re.compile(r"^[A-Z_]+$")
pro_keys_dict = dict(
[(x, rfc2217.__dict__[x]) for x in dir(rfc2217) if key_match.match(x)]
)
globals().update(pro_keys_dict)
from serial.rfc2217 import (
TelnetOption,
TelnetSubnegotiation,
RFC2217_PARITY_MAP,
RFC2217_STOPBIT_MAP,
)
My proposal:
from serial import (FEW_STUFFS)
from serial.rfc2217 import *
from serial import serialutil
This will really improve the static checking of the module.
Any idea why this code is more complex than a default import?
@sebastien.petitdemange @matias.guijarro any idea?