Skip to content

Forward reference fails in type annotations #1578

@ariep

Description

@ariep

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):

  • Errbot version: 6.1.9
  • OS version: debian 11 (in docker container)
  • Python version: 3.9.13 (in docker container)
  • Using a virtual environment: no
  • Using Docker: yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions