Skip to content

ReturnWithArgsInsideGenerator was removed from API in 2.5.0 - how to update code? #733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
haesleinhuepf opened this issue Oct 6, 2022 · 9 comments

Comments

@haesleinhuepf
Copy link

Hi all,

I just noticed that the napari-script-editor, a plugin I maintain, stopped working with pyflakes 2.5.0 because this function is missing from the API (full error log below):

AttributeError: module 'pyflakes.messages' has no attribute 'ReturnWithArgsInsideGenerator'

I'm just wondering, is there some transition guide for how to update dependent code from pyflakes 2.4.0 to 2.5.0 ?

Thanks!

Best,
Robert

Full error log:

===================== Errors for plugin 'napari-script-editor' =====================

napari version: 0.4.15


ERROR #1: Error while importing module napari_script_editor ---------------------

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~\miniconda3\envs\bio_39\lib\site-packages\napari_plugin_engine\manager.py:318, in PluginManager._load_and_register(self=, mod_name='napari_script_editor', plugin_name='napari-script-editor')
    317 try:
--> 318     module = load(mod_name)
        mod_name = 'napari_script_editor'
    319     if self.is_registered(module):

File ~\miniconda3\envs\bio_39\lib\site-packages\napari_plugin_engine\manager.py:1042, in load(value='napari_script_editor')
   1041     raise ValueError(f"malformed entry point string: {value}")
-> 1042 module = importlib.import_module(match.group('module'))
        match = 
   1043 attrs = filter(None, (match.group('attr') or '').split('.'))

File ~\miniconda3\envs\bio_39\lib\importlib\__init__.py:127, in import_module(name='napari_script_editor', package=None)
    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
        level = 0
        name = 'napari_script_editor'
        name[level:] = 'napari_script_editor'
        package = None
        _bootstrap = 

File :1030, in _gcd_import(name='napari_script_editor', package=None, level=0)

File :1007, in _find_and_load(name='napari_script_editor', import_=)

File :986, in _find_and_load_unlocked(name='napari_script_editor', import_=)

File :680, in _load_unlocked(spec=ModuleSpec(name='napari_script_editor', loader=

File :850, in exec_module(self=, module=)

File :228, in _call_with_frames_removed(f=, *args=( at 0x0000023DA781D0E0, fil...ckages\napari_script_editor\__init__.py", line 2>, {'__builtins__': {'ArithmeticError': , 'AssertionError': , 'AttributeError': , 'BaseException': , 'BlockingIOError': , 'BrokenPipeError': , 'BufferError': , 'BytesWarning': , 'ChildProcessError': , 'ConnectionAbortedError': , ...}, '__cached__': r'C:\Users\rober\miniconda3\envs\bio_39\lib\site-p...script_editor\__pycache__\__init__.cpython-39.pyc', '__doc__': None, '__file__': r'C:\Users\rober\miniconda3\envs\bio_39\lib\site-packages\napari_script_editor\__init__.py', '__loader__': , '__name__': 'napari_script_editor', '__package__': 'napari_script_editor', '__path__': [r'C:\Users\rober\miniconda3\envs\bio_39\lib\site-packages\napari_script_editor'], '__spec__': ModuleSpec(name='napari_script_editor', loader=

File ~\miniconda3\envs\bio_39\lib\site-packages\napari_script_editor\__init__.py:7, in 
      2 __version__ = "0.2.8"
----> 7 from ._dock_widget import napari_experimental_provide_dock_widget, ScriptEditor
      9 from ._scripts_directory import _search_scripts

File ~\miniconda3\envs\bio_39\lib\site-packages\napari_script_editor\_dock_widget.py:5, in 
      3 from qtpy.QtCore import QTimer
----> 5 from pyqode.python.backend import server
      6 from pyqode.python.widgets import PyCodeEdit

File ~\miniconda3\envs\bio_39\lib\site-packages\pyqode\python\backend\__init__.py:7, in 
      2 """
      3 The backend package contains everything needed to implement the
      4 server side of a python editor.
      5 
      6 """
----> 7 from .workers import calltips
      8 from .workers import defined_names

File ~\miniconda3\envs\bio_39\lib\site-packages\pyqode\python\backend\workers.py:185, in 
    180         return messages
    183 PYFLAKES_ERROR_MESSAGES = [
    184     messages.DoctestSyntaxError,
--> 185     messages.ReturnWithArgsInsideGenerator,
        messages = 
    186     messages.UndefinedExport,
    187     messages.UndefinedName,
    188     messages.UndefinedLocal
    189 ]
    192 def run_pyflakes(request_data):

AttributeError: module 'pyflakes.messages' has no attribute 'ReturnWithArgsInsideGenerator'

The above exception was the direct cause of the following exception:

PluginImportError                         Traceback (most recent call last)
File ~\miniconda3\envs\bio_39\lib\site-packages\napari_plugin_engine\manager.py:264, in PluginManager.discover(self=, path=None, entry_point=None, prefix=None, ignore_errors=True)
    261     continue
    263 try:
--> 264     if self._load_and_register(mod_name, name):
        name = 'napari-plot-profile'
        mod_name = 'napari_plot_profile'
        self = 
    265         count += 1
    266         self._id_counts[name] = 1

File ~\miniconda3\envs\bio_39\lib\site-packages\napari_plugin_engine\manager.py:322, in PluginManager._load_and_register(self=, mod_name='napari_script_editor', plugin_name='napari-script-editor')
    320         return None
    321 except Exception as exc:
--> 322     raise PluginImportError(
        plugin_name = 'napari-script-editor'
    323         f'Error while importing module {mod_name}',
    324         plugin_name=plugin_name,
    325         cause=exc,
    326     )
    327 if not (inspect.isclass(module) or inspect.ismodule(module)):
    328     raise PluginRegistrationError(
    329         f'Plugin "{plugin_name}" declared entry_point "{mod_name}"'
    330         ' which is neither a module nor a class.',
    331         plugin=module,
    332         plugin_name=plugin_name,
    333     )

PluginImportError: Error while importing module napari_script_editor
================================================================================
@asottile
Copy link
Member

asottile commented Oct 6, 2022

yes, it's fine because pyflakes no longer supports python 2

@asottile asottile closed this as completed Oct 6, 2022
@haesleinhuepf
Copy link
Author

Hey @asottile ,

thanks for the feedback. Would you mind answering my question?

I'm just wondering, is there some transition guide for how to update dependent code from pyflakes 2.4.0 to 2.5.0 ?

I'm receiving the above error message in Python 3.9.

Thanks!

Best,
Robert

@asottile
Copy link
Member

asottile commented Oct 6, 2022

I'm not sure what your question is, or perhaps it's obvious to me that if something is accessing something that doesn't exist it needs to stop doing that -- could you clarify what you're confused about?

@haesleinhuepf
Copy link
Author

I'm wondering how I can update that code, which worked with pyflakes 2.4.0 to make it work with pyflakes 2.5.0. Is there a transition guide document somewhere that helps with those things?

 183 PYFLAKES_ERROR_MESSAGES = [
    184     messages.DoctestSyntaxError,
    185     messages.ReturnWithArgsInsideGenerator,
    186     messages.UndefinedExport,
    187     messages.UndefinedName,
    188     messages.UndefinedLocal
    189 ]

The error happens in line 185, becaue this doesn't exist anymore. Is there a replacement?

Thanks!

@sigmavirus24
Copy link
Member

@haesleinhuepf Anthony has clearly stated it doesn't exist and was removed with python 2 support. The error it represents is no longer an error in Python 3 thus it was removed. Is that clearer?

@haesleinhuepf
Copy link
Author

Ah, so you're saying I can comment out that line to make it work again. Thanks for your support!

@CommanderPho
Copy link

I just wanted to add that @haesleinhuepf 's question seems well-poised and clear enough to me. I encountered a the same error while trying to run an example for pyqode a custom pyqt code-editor widget. I didn't build the library, I'm merely an end-user and a breaking change in pyflakes means that the current conda repo no longer works. I'll comment out the offending line as suggested.

yes, it's fine because pyflakes no longer supports python 2

Fine for who? It doesn't fix the error I'm encountering. It's not immediately obvious how removal of ReturnWithArgsInsideGenerator relates to removal of Python 2 support. The question states that we're seeking a replacement that could be swapped in without breaking functionality. I suppose I'm just being lazy by not digging into the history of PyFlakes, but it's just a dependency of a dependency of an example.

@asottile
Copy link
Member

it's trivial to figure out what happened -- teaching one to fish:

$ git log -G ReturnWithArgsInsideGenerator  | head -5
commit 2246217295dc8cb30ef4a7b9d8dc449ce32e603a
Author: Anthony Sottile <[email protected]>
Date:   Sun Jun 12 17:07:21 2022 -0400

    burn the bridges with python 2.x (#707)
asottile@asottile-sentry:/tmp/pyflakes
$ git show --format= 2246217295dc8cb30ef4a7b9d8dc449ce32e603a -- pyflakes/messages.py | cat
diff --git a/pyflakes/messages.py b/pyflakes/messages.py
index 5a2f0ce..2d08112 100644
--- a/pyflakes/messages.py
+++ b/pyflakes/messages.py
@@ -3,18 +3,18 @@ Provide the class Message and its subclasses.
 """
 
 
-class Message(object):
+class Message:
     message = ''
     message_args = ()
 
     def __init__(self, filename, loc):
         self.filename = filename
         self.lineno = loc.lineno
-        self.col = getattr(loc, 'col_offset', 0)
+        self.col = loc.col_offset
 
     def __str__(self):
-        return '%s:%s:%s: %s' % (self.filename, self.lineno, self.col+1,
-                                 self.message % self.message_args)
+        return '{}:{}:{}: {}'.format(self.filename, self.lineno, self.col+1,
+                                     self.message % self.message_args)
 
 
 class UnusedImport(Message):
@@ -33,14 +33,6 @@ class RedefinedWhileUnused(Message):
         self.message_args = (name, orig_loc.lineno)
 
 
-class RedefinedInListComp(Message):
-    message = 'list comprehension redefines %r from line %r'
-
-    def __init__(self, filename, loc, name, orig_loc):
-        Message.__init__(self, filename, loc)
-        self.message_args = (name, orig_loc.lineno)
-
-
 class ImportShadowedByLoopVar(Message):
     message = 'import %r from line %r shadowed by loop variable'
 
@@ -168,13 +160,6 @@ class UnusedVariable(Message):
         self.message_args = (names,)
 
 
-class ReturnWithArgsInsideGenerator(Message):
-    """
-    Indicates a return statement with arguments inside a generator.
-    """
-    message = '\'return\' with argument inside generator'
-
-
 class ReturnOutsideFunction(Message):
     """
     Indicates a return statement outside of a function/method.

if you're integrating with pyflakes as a library it's kinda on you to keep up with the changes -- we can't be responsible for your integrations. the implementation of the pyflakes tool isn't a public interface (entirely undocumented) or really supported so using the internals in that way is at your own support (this is the reason for example flake8 carefully selects the versions of pyflakes)

@CommanderPho
Copy link

Thank you @asottile for taking the time to reply. All I see in the diff is that the function was removed, which I agree is trivial and the part that I could do on my own without help from the community. Unfortunately this does little to help me resolve the problem or answer the question asked.

The second part of your comment on the other hand better explains the situation (and why a changing public interface isn't this library's problem and can't be expected or relied upon). Furthermore suggests a potential solution for the issue (carefully select and pin the version of pyflakes in my library like flake8 does). Thanks again for your time and consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants