Skip to content

Not compatible with Python 3.14 #27

Open

Description

@SnoopJ

flake8-future-import uses ast.Str which has been removed in Python 3.14.

click for example failure stack trace
Traceback (most recent call last):
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/plugins/finder.py", line 291, in _load_plugin
    obj = plugin.entry_point.load()
  File "/home/jgerity/.pyenv/versions/3.14.0rc1/lib/python3.14/importlib/metadata/__init__.py", line 179, in load
    module = import_module(match.group('module'))
  File "/home/jgerity/.pyenv/versions/3.14.0rc1/lib/python3.14/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1398, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1371, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1342, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 938, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 762, in exec_module
  File "<frozen importlib._bootstrap>", line 491, in _call_with_frames_removed
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8_future_import.py", line 17, in <module>
    from ast import NodeVisitor, Str, Module, parse
ImportError: cannot import name 'Str' from 'ast' (/home/jgerity/.pyenv/versions/3.14.0rc1/lib/python3.14/ast.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/bin/flake8", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/main/cli.py", line 23, in main
    app.run(argv)
    ~~~~~~~^^^^^^
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/main/application.py", line 198, in run
    self._run(argv)
    ~~~~~~~~~^^^^^^
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/main/application.py", line 186, in _run
    self.initialize(argv)
    ~~~~~~~~~~~~~~~^^^^^^
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/main/application.py", line 165, in initialize
    self.plugins, self.options = parse_args(argv)
                                 ~~~~~~~~~~^^^^^^
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/options/parse_args.py", line 42, in parse_args
    plugins = finder.load_plugins(raw_plugins, plugin_opts)
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/plugins/finder.py", line 365, in load_plugins
    return _classify_plugins(_import_plugins(plugins, opts), opts)
                             ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/plugins/finder.py", line 307, in _import_plugins
    return [_load_plugin(p) for p in plugins]
            ~~~~~~~~~~~~^^^
  File "/media/nas/repos/sopel.git/3.14.0rc1_venv/lib/python3.14/site-packages/flake8/plugins/finder.py", line 293, in _load_plugin
    raise FailedToLoadPlugin(plugin.package, e)
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "flake8-future-import" due to cannot import name 'Str' from 'ast' (/home/jgerity/.pyenv/versions/3.14.0rc1/lib/python3.14/ast.py).

Here is a patch that should resolve the issue:

diff --git a/flake8_future_import.py b/flake8_future_import.py
index 444b02c..269f3f0 100755
--- a/flake8_future_import.py
+++ b/flake8_future_import.py
@@ -14,7 +14,7 @@ try:
 except ImportError as e:
     argparse = e
 
-from ast import NodeVisitor, Str, Module, parse
+from ast import Constant, NodeVisitor, Module, parse
 
 __version__ = '0.4.7'
 
@@ -31,7 +31,7 @@ class FutureImportVisitor(NodeVisitor):
             self.future_imports += [node]
 
     def visit_Expr(self, node):
-        if not isinstance(node.value, Str) or node.value.col_offset != 0:
+        if not (isinstance(node.value, Constant) and isinstance(node.value.value, str)) or node.value.col_offset != 0:
             self._uses_code = True
 
     def generic_visit(self, node):

Activity

  1. added a commit that references this issue on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

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