Skip to content

Recognize and replace if sys.version_info[0] blocks #918

Open
@EwoutH

Description

pyupgrade currently does detect the if sys.version_info < (3, 5): syntax, it doesn't recognize the lesser but still sometimes used if sys.version_info[0] < 3: syntax in if or if-else blocks. It would be a nice feature if pyupgrade also could recognize and automatically replace such blocks.

A few examples I encountered in the wild:

if sys.version_info[0] < 3:
    import shutil
    shutil.rmtree(cls._tmpdir)
else:
    cls._tmpdir.cleanup()
if (sys.version_info[0] >=3 and
        isinstance(node, StringNode) and
        node.unicode_value is not None):
    return (node.unicode_value, node.pos)
return (node.compile_time_value(empty_scope), node.pos)
if sys.version_info[0] != 2:
    self.assertTrue(StringEncoding.string_contains_lone_surrogates("\uD800\uDFFF"))

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions