Skip to content

Pylint: unneessary-comprehension #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evaherrada opened this issue Mar 12, 2020 · 2 comments
Closed

Pylint: unneessary-comprehension #16

evaherrada opened this issue Mar 12, 2020 · 2 comments

Comments

@evaherrada
Copy link
Collaborator

Pylint's output (if you look at the actions report, there were two other issues pylint had, but they were pretty straightforward)

************* Module adafruit_miniesptool
adafruit_miniesptool.py:330:0: R1721: Unnecessary use of a comprehension (unnecessary-comprehension)
adafruit_miniesptool.py:331:0: R1721: Unnecessary use of a comprehension (unnecessary-comprehension)
adafruit_miniesptool.py:332:0: R1721: Unnecessary use of a comprehension (unnecessary-comprehension)

Not really sure what's going on here, but this is the code that pylint didn't like:

        packet = [0xC0, 0x00]  # direction
        packet.append(opcode)
        packet += [x for x in struct.pack("H", len(buffer))]
        packet += [x for x in self.slip_encode(struct.pack("I", checksum))]
        packet += [x for x in self.slip_encode(buffer)]
        packet += [0xC0]

Referencing main issue: adafruit/Adafruit_CircuitPython_Bundle#232

@tannewt
Copy link
Member

tannewt commented Mar 13, 2020

I think it because the first portion of a comprehension is usually more than just x again. Usually there is a transformation there.

My guess is that these were used to convert sequences to lists. Instead, I'd recommend changing them to packet.extend(struct.pack("H", len(buffer))). I believe that will work to append to the packet list.

@kattni
Copy link
Contributor

kattni commented Mar 30, 2020

I believe this is completed.

@kattni kattni closed this as completed Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants