routes property returns None #1184
Replies: 2 comments 1 reply
-
I can't replicate the issue you're describing?... >>> from starlette.applications import Starlette
>>> s = Starlette()
>>> s.routes
[] |
Beta Was this translation helpful? Give feedback.
-
Using the reply above, I managed to replicate the behavior you described on the current master branch (d26f44b). The behavior is in line with the following default value: starlette/starlette/routing.py Line 340 in b7aeae7 (Staticfiles does not define a routes property)
Given all that, a change to return an empty list would be fairly trivial. The main problem/question I see is that returning a None when no routes exist is fairly standard behavior in many parts of the codebase. None is the default value in the As far as I could tell, this behavior is not documented, so I'm not sure what the preferred behavior would be, but an argument could be made either way. Regardless, it may make sense to standardize this behavior for different API components, though I imagine this may be a breaking change. |
Beta Was this translation helpful? Give feedback.
-
Checklist
master
.Describe the bug
Elastic apm tries to collect information regarding the route by accessing routes property.
the implementations of BaseRoute such as Route, Mount says the return type is
typing.List[BaseRoute]
.In case that the app doesn't have "routes" it will return None.
Expected behavior
routes property will return empty list
Actual behavior
routes property will returns None
Debugging material
Environment
Beta Was this translation helpful? Give feedback.
All reactions