falconry / falcon

The no-magic web data plane API and microservices framework for Python developers, with a focus on reliability, correctness, and performance at scale.
https://falcon.readthedocs.io/en/stable/
Apache License 2.0
9.51k stars 937 forks source link

Can't debug Falcon in Python 3.10 #2112

Closed YossiTamari closed 1 year ago

YossiTamari commented 1 year ago

At least in PyCharm, when running in debug mode (so with Type Checking on), in Python 3.10 specifically, importing falcon adds a a property called dict to Python's collections. The property is a dict of media type handlers. That causes a crash later when collections tries to do dict(...). (Tested in Falcon 3.1.0: falcon-3.1.0-cp310-cp310-macosx_10_15_x86_64.whl)

To reproduce simply debug this code:

import collections
import falcon
print(collections.dict)

The output when running with a debugger is:

{'application/json': <falcon.media.json.JSONHandler object at 0x120e59ba0>, 'application/x-www-form-urlencoded': <falcon.media.urlencoded.URLEncodedFormHandler object at 0x120e59c00>}

When running without a debugger it correctly raises AttributeError: module 'collections' has no attribute 'dict'

Additional Information: This seems to happen inside falcon/__init__.py in the call to from falcon.app import API. Putting a breakpoint inside falcon.app did not work. For some reason, the debugger would not stop there.

CaselIT commented 1 year ago

Hi,

This is a pycharm bug, I'm not sure how can we fix this our side. The falcon library is not doing that anywhere.

A collegue of mine already reported it on pycharm side https://youtrack.jetbrains.com/issue/PY-54853