Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
bliss
bliss
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 515
    • Issues 515
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Jira
    • Jira
  • Merge Requests 123
    • Merge Requests 123
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Bliss
  • blissbliss
  • Issues
  • #1834

Closed
Open
Opened Jul 03, 2020 by Valentin Valls@valentin.valls
  • Report abuse
  • New issue
Report abuse New issue

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?

Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
2
Labels
Cleanup question
Assign labels
  • View project labels
Reference: bliss/bliss#1834