Skip to content
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

Forward reference fails in type annotations #1578

Closed
ariep opened this issue Jun 18, 2022 · 2 comments · Fixed by #1580
Closed

Forward reference fails in type annotations #1578

ariep opened this issue Jun 18, 2022 · 2 comments · Fixed by #1580

Comments

@ariep
Copy link
Contributor

ariep commented Jun 18, 2022

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
@nzlosh
Copy link
Contributor

nzlosh commented Jun 19, 2022

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

@ariep
Copy link
Contributor Author

ariep commented Jun 19, 2022

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

Done: #1580

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

Successfully merging a pull request may close this issue.

2 participants