Skip to content

Feature idea/question: cleanup conditionals on sys.version_info #488

@neutrinoceros

Description

@neutrinoceros

This is more of a question at this point: I wonder if it would be possible to do this with pyupgrade.
If it is, I'll attempt to write a patch, otherwise you can just close this !

input

assuming we run pyupgrade with the --py39 flag

import sys

if sys.version_info < (3, 9):
    print("this should be cleaned up")
else:
    print("this is the message we should keep (dedent)")

if sys.version_info > (3, 8):
    print("this is the message we should keep (dedent)")
else:
    print("this should be cleaned up")

if sys.version_info >= (3, 8):
    print("this is the message we should keep (dedent)")
else:
    print("this should be cleaned up")

if sys.version_info <= (3, 9):
    print("nothing to do here")
else:
    print("both branches are still valid")

output

import sys

print("this is the message we should keep (dedent)")

print("this is the message we should keep (dedent)")

print("this is the message we should keep (dedent)")

if sys.version_info <= (3, 9):
    print("nothing to do here")
else:
    print("both branches are still valid")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions