Skip to content
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

Adding skip_blank option #36

Closed
wants to merge 3 commits into from
Closed

Conversation

aroberge
Copy link
Contributor

I've done a first implementation of skip_blank option. I chose this name instead of no_skip_blank that I had mentioned before since it seemed more natural to use a name that corresponded to the default.

Here's an example, first showing the default result:

Traceback (most recent call last):
 File "C:\Users\Andre\github\stack_data\example.py", line 8, in <module>
       1 | import stack_data
       3 | stack_data.Formatter().set_hook()
       5 | word = "word"
-->    8 | nb_ = len(letter
                 ^^^^^^^^^^
       9 |             for letter
                       ^^^^^^^^^^
      10 |               in
                       ^^^^
      11 |             word)
                       ^^^^^
      13 | pass
TypeError: object of type 'generator' has no len()

Next, with this new option enabled, by setting skip_blank=False:

Traceback (most recent call last):
 File "C:\Users\Andre\github\stack_data\example.py", line 8, in <module>
       1 | import stack_data
       2 |
       3 | stack_data.Formatter(skip_blank=False).set_hook()
       4 |
       5 | word = "word"
       : |
-->    8 | nb_ = len(letter
                 ^^^^^^^^^^
       9 |             for letter
                       ^^^^^^^^^^
      10 |               in
                       ^^^^
      11 |             word)
                       ^^^^^
      12 |
      13 | pass
TypeError: object of type 'generator' has no len()

I have also fixed a bug with the multiline highlighting when the "executing piece" included a blank line. Here's an example before the bug fix:

Traceback (most recent call last):
 File "C:\Users\Andre\github\stack_data\example.py", line 8, in <module>
       1 | import stack_data
       3 | stack_data.Formatter().set_hook()
       5 | word = "word"
-->    8 | nb_ = len(letter
                 ^^^^^^^^^^
       9 |

      10 |             for letter
           ^^^^^^^^^^^^^^^^^^^^^^
      11 |               in
           ^^^^^^^^^^^^^^^^
      12 |             word)
           ^^^^^^^^^^^^^^^^^
      14 | pass
TypeError: object of type 'generator' has no len()

And the result after fixing the bug:

Traceback (most recent call last):
 File "C:\Users\Andre\github\stack_data\example.py", line 8, in <module>
       1 | import stack_data
       3 | stack_data.Formatter().set_hook()
       5 | word = "word"
-->    8 | nb_ = len(letter
                 ^^^^^^^^^^
       9 |

      10 |             for letter
                       ^^^^^^^^^^
      11 |               in
                       ^^^^
      12 |             word)
                       ^^^^^
      14 | pass
TypeError: object of type 'generator' has no len()

I have not yet created unit tests.

@alexmojaki
Copy link
Owner

Formatters are not the heart of this library. They're not used by futurecoder or IPython. I don't think they're used by friendly...right? This option needs to an argument of the Options class and it needs to affect the behaviour of core objects like FrameInfo. For example, it could make FrameInfo.lines include Line objects that are blank. Probably a better way to satisfy your use case would be to make it yield a third type of object (an alternative to Line and LineGap) representing a sequence of one or more consecutive blank lines.

@aroberge
Copy link
Contributor Author

Currently, friendly_traceback does not make correct use of stack_data and I was thinking that I would use this new option via the formatter. But I will try to implement it the way you are suggesting.

@alexmojaki alexmojaki closed this Aug 14, 2022
@alexmojaki alexmojaki reopened this Aug 14, 2022
@alexmojaki
Copy link
Owner

Sorry, I started writing something and then decided to discard it, and I clicked before I realised I wasn't clicking on a 'Cancel' button.

@aroberge
Copy link
Contributor Author

I will close the pull request as I had not updated my fork before working. I will do this now to start fresh.

@aroberge aroberge closed this Aug 14, 2022
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

Successfully merging this pull request may close these issues.

2 participants