Skip to content

Commit ac38287

Browse files
committed
Fixed custom traversal and typehints in tests.
1 parent ed68dc9 commit ac38287

5 files changed

Lines changed: 12 additions & 7 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dependencies = [
4848
test = [
4949
"blinker",
5050
"httpx",
51+
"packaging",
5152
"pytest",
5253
"python-multipart",
5354
"webob",

rollbar/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,8 @@ def wrapper(event, context):
628628

629629

630630
def report_exc_info(
631-
exc_info: tuple[type[BaseException], BaseException, types.TracebackType] | tuple[None, None, None] | None = None,
631+
exc_info: tuple[type[BaseException], BaseException, types.TracebackType | None] | tuple[
632+
None, None, None] | None = None,
632633
request=None, extra_data=None, payload_data=None, level=None, **kw):
633634
"""
634635
Reports an exception to Rollbar, using exc_info (from calling sys.exc_info())

rollbar/lib/traverse.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ def traverse(
173173
elif obj_type is PATH:
174174
return path_handler(obj, key=key)
175175
elif obj_type is DEFAULT:
176-
for handler_type, handler in custom_handlers.items():
177-
# Only attempt isinstance checks when the key is a type (or tuple of types).
178-
if isinstance(handler_type, (type, tuple)) and isinstance(obj, handler_type):
176+
for handler_type, handler in (custom_handlers or {}).items():
177+
# Check the full module path first e.g. "my_module.MyClass" or "builtin.complex"
178+
if f"{type(obj).__module__}.{type(obj).__name__}" == handler_type:
179+
return handler(obj, key=key)
180+
# Fallback to just the name e.g. "MyClass" or "complex".
181+
if type(obj).__name__ == handler_type:
179182
return handler(obj, key=key)
180183
except:
181184
# use the default handler for unknown object types

rollbar/lib/type_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Hashable
3+
from typing import Hashable, Any
44

55
from rollbar.lib import binary_type, string_types
66

@@ -20,7 +20,7 @@
2020
PATH = 7
2121

2222

23-
def get_type(obj):
23+
def get_type(obj: Any) -> int:
2424
if isinstance(obj, (string_types, binary_type)):
2525
return STRING
2626

rollbar/test/starlette_tests/test_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ async def root(original_request):
307307
return PlainTextResponse('OK')
308308

309309
app = Starlette(routes=[
310-
Route('/{param}', endpoint=root),
310+
Route('/', endpoint=root),
311311
])
312312
app.add_middleware(ReporterMiddleware)
313313

0 commit comments

Comments
 (0)