question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

python x.7 code will break py3.7

See original GitHub issue

https://github.com/srsudar/eg/blob/f2968471010fccf9e066d3064903eb49675ff766/eg/color.py#L90

One of the color functions only checks if python version is < x.7. However python3.7 is now the default py version so this might start breaking systems with newer python executables.

    def _color_helper(s, text, pattern, repl):
        # < 2.7 didn't have the flags named argument.
        if sys.version_info[1] < 7:
            compiled_pattern = re.compile(pattern, re.MULTILINE)
            return re.sub(
                compiled_pattern,
                repl,
                text
            )
        else:
            return re.sub(
                pattern,
                repl,
                text,
                flags=re.MULTILINE
)

So couldn’t we do if sys.version_info < (2,7):

And be more explicit?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
srsudarcommented, Aug 18, 2018

#76 employs your suggested fix. I didn’t realize you could compare tuples like that. I’m surprised there haven’t been any complaints given that 3.7 was apparently released over a month ago. If anyone chimes in that this is affecting them I will release immediately, otherwise I’ll release around the 5th of next month on my regular schedule.

This also tipped me off that switching to py.test means the tests don’t run on <2.7.

0reactions
farisachugthaicommented, Aug 19, 2018

Yup!

dir(sys.version_info)

Returns _lt_ and __gt__so you get intuitive comparisons like that. Gotta love the way the standard library implements operator overloading

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 3 - break statement - Tutorialspoint
The break statement is used for premature termination of the current loop. After abandoning the loop, execution at the next statement is resumed, ......
Read more >
“How To Use Break, Continue, and Pass Statements when ...
In Python, the break statement provides you with the opportunity to exit out of a loop when an external condition is triggered. You'll...
Read more >
Python break and continue (With Examples) - Programiz
The break statement is used to terminate the loop immediately when it is encountered. The syntax of the break statement is: break. Working...
Read more >
4. More Control Flow Tools — Python 3.11.1 documentation
The break statement, like in C, breaks out of the innermost enclosing for or while loop. Loop statements may have an else clause;...
Read more >
Pass, Break and Continue in Python 3 | by Josh Robin - Medium
One way to do this is by looping through each character in the string until the first space, and then using break to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found