Skip to content

Spacing around colons can crash pycodestyle_magic #20

Open

Description

@cmichal2

Using pycodestyle in "cell-at-a-time" mode, with %%pycodestyle as the first line in a cell seems to be very sensitive the spacing around colons.

In particular, a space before a colon that introduces a new block, such as:
for i in range(5) :
will crash it with an error that appears to be related to parsing windows drive names, though I'm using this on linux.
Similar errors occur in defining a dictionary if there is a space before a colon or no space after a colon.

 ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-ec9d1225e653> in <module>()
----> 1 get_ipython().run_cell_magic('pycodestyle', '', 'for i in range(4) :\n    pass')

/usr/lib64/python3.6/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2115             magic_arg_s = self.var_expand(line, stack_depth)
   2116             with self.builtin_trap:
-> 2117                 result = fn(magic_arg_s, cell)
   2118             return result
   2119 

/home/p210nb/.local/lib64/python3.6/site-packages/pycodestyle_magic.py in pycodestyle(line, cell, auto)
    173         #logger.info(line)
    174         # on windows drive path also contains :
--> 175         line, col, error = line.split(':')[-4:]
    176         # do not subtract 1 for line for %%pycodestyle, inc pre py3.6 string
    177         if auto:

ValueError: too many values to unpack (expected 3)


Activity

  1. mattijn commented on Dec 9, 2019

    @mattijn
    Owner

    Thanks for raising the issue!
    If I try to emulate the error you got I got no hard errors, but mainly styling errors as such:
    image

    Could you provide more information on the version of ipython \ pycodestyle_magic etc. Maybe we can find some discrepancy there?

  2. mattijn commented on Dec 9, 2019

    @mattijn
    Owner

    Oh wait. I didn't read your issue right.. I can reproduce the error. Hm, indeed strange!

  3. mattijn commented on Dec 9, 2019

    @mattijn
    Owner

    This line:

    line, col, error = line.split(':')[-4:] 

    splits on :, which goes wrong when there is an : in the error. I can replace it with the following

    line_split = line.split(' ')
    line, col, _ = line_split[0].split(':')[-3:]
    error = ' '.join(line_split[1::]) 

    But I broke my python print() function doing so.. It seems. But for now, it doesn't print anything anymore. Will check soon on a windows machine if there is this behaviour also occurs..

  4. added this to the v0.0.6 milestone on Feb 2, 2020
  5. added 3 commits that reference this issue on Oct 3, 2022
    b681c96
    474946a
    9243556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions