Skip to content

from __future__ imports are not placed at the beginning of the file #263

@ning-y

Description

@ning-y

I ran modernize on https://github.com/brianjamesschmidt/gim3e/, an older python2 module. When trying to use the now-modernized module, Python 3.12.8 complained that "from future imports must occur at the beginning of the file."

It would be good if modernize handled this when adding from __future__ import ... statements.

Traceback (most recent call last):
  File "/home/ning/repos/gim3e/gim3e/test_all.py", line 3, in <module>
    from gim3e.test import test_all
  File "/home/ning/repos/gim3e/lib/python3.12/site-packages/gim3e/test/__init__.py", line 60, in <module>
    suite = create_test_suite()
            ^^^^^^^^^^^^^^^^^^^
  File "/home/ning/repos/gim3e/lib/python3.12/site-packages/gim3e/test/__init__.py", line 55, in create_test_suite
    exec("from . import " + test_name)
  File "<string>", line 1, in <module>
  File "/home/ning/repos/gim3e/lib/python3.12/site-packages/gim3e/test/unit_tests.py", line 34, in <module>
    import gim3e.core.gim3e as gim3e
  File "/home/ning/repos/gim3e/lib/python3.12/site-packages/gim3e/core/gim3e.py", line 3
    from __future__ import print_function
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: from __future__ imports must occur at the beginning of the file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions