nsetzer / mpgameserver

Python Multiplayer UDP Game Server
GNU Lesser General Public License v2.1
43 stars 6 forks source link

Using ServerMessageDispatcher or ClientMessageDispatcher with future annotations #3

Closed Aman-Anas closed 11 months ago

Aman-Anas commented 1 year ago

In my project, I use the from __future__ import annotations syntax in my resources scripts, but when this flag is activated, the message dispatcher fails to register the message types. This is because the new annotation system converts the types to strings. The result is that I get DispatchErrors despite having registered the types.

I found a relatively simple solution, which is to add the new eval_str argument to the inspect.signature() calls in dispatch.py. I think it may only be present in 3.10 though, so maybe there would need to be an alternative for 3.9 support. This solution seems to work well for me though.

sig = inspect.signature(method, eval_str=True) # New argument here
args = list(sig.parameters.items())
nsetzer commented 1 year ago

Hello @Aman-Anas, If you make a PR with this change Ill take a look at support for 3.9.

Aman-Anas commented 11 months ago

Closing this issue since it's been already been fixed and merged. Thanks!