errbotio / errbot

Errbot is a chatbot, a daemon that connects to your favorite chat service and bring your tools and some fun into the conversation.
http://errbot.io
GNU General Public License v3.0
3.12k stars 612 forks source link

Forward reference fails in type annotations #1578

Closed ariep closed 2 years ago

ariep commented 2 years ago

Describe the bug When running the latest release 6.1.9 from docker with the XMPP backend, errbot fails to start, giving the following error:

2022-06-18 15:05:34,523 ERROR    errbot.bootstrap          Unable to load or configure the backend.                                                           
Traceback (most recent call last):                                                                                                                            
  File "/usr/local/lib/python3.9/site-packages/errbot/bootstrap.py", line 181, in setup_bot                                                                   
    bot = backendpm.load_plugin()                                                                                                                             
  File "/usr/local/lib/python3.9/site-packages/errbot/backend_plugin_manager.py", line 62, in load_plugin                                                     
    plugin_classes = self.plugin_info.load_plugin_classes(                                                                                                    
  File "/usr/local/lib/python3.9/site-packages/errbot/plugin_info.py", line 100, in load_plugin_classes                                                       
    spec.loader.exec_module(modu1e)                                                                                                                           
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module      
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/errbot/backends/xmpp.py", line 123, in <module>
    class XMPPRoom(XMPPIdentifier, Room):
  File "/usr/local/lib/python3.9/site-packages/errbot/backends/xmpp.py", line 252, in XMPPRoom
    def occupants(self) -> List[XMPPRoomOccupant]:
NameError: name 'XMPPRoomOccupant' is not defined

This also happens with a docker image built manually from latest master.

The problem is that the type annotation of the XMPPRoom.occupants function references the XMPPRoomOccupant class which is not yet defined at that point.

To Reproduce Run errbotio/errbot:6.1.9 with a config that has backend XMPP.

Expected behavior I would expect this to not fail. Indeed, adding a line from __future__ import annotations to the top of errbot/backends/xmpp.py solves the problem.

Environment (please complete the following information):

nzlosh commented 2 years ago

Thank your for the report, can you please open a PR with the fix.

ariep commented 2 years ago

Thank your for the report, can you please open a PR with the fix.

Done: https://github.com/errbotio/errbot/pull/1580