File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def additional_handler(event_instance):
2626
2727This example shows how ``core.context_with_data()`` can be replaced by `core.context_with_event()`::
2828
29- @span_context
29+ @context_event
3030 class TestContextEvent(SpanContextEvent):
3131 # SpanContextEvent requires this attributes
3232 event_name = "test.event"
@@ -115,11 +115,14 @@ def context_event(cls: Any) -> Any:
115115 class MyEvent(SpanContextEvent):
116116 url: str # Automatically gets event_field() applied
117117 """
118- annotations = getattr (cls , "__annotations__" , {})
118+
119+ annotations = cls .__dict__ .get ("__annotations__" , {})
119120
120121 # For each annotated field without a default, set it to event_field()
121122 for name , _ in annotations .items ():
122- if not hasattr (cls , name ):
123+ # Only apply `event_field()` for fields that don't define a default value
124+ # in the class body.
125+ if name not in cls .__dict__ :
123126 setattr (cls , name , event_field ())
124127
125128 return dataclass (cls )
Original file line number Diff line number Diff line change 1+ import sys
12from types import TracebackType
23from typing import Optional
34from typing import Tuple
@@ -78,8 +79,12 @@ def _on_context_ended(
7879 assert len (_listeners [f"context.ended.{ TestContextEvent .event_name } " ].values ()) == 1
7980
8081
82+ @pytest .mark .skipif (sys .version_info < (3 , 10 ), reason = "Requires Python 3.10+" )
8183def test_context_event_enforce_kwargs_error ():
82- """Test that missing required fields raise TypeError."""
84+ """Test that missing required fields raise TypeError.
85+ On Python 3.9, we create a default value to every attributes because kw_only
86+ is not available in dataclass field. Therefore we skip the test
87+ """
8388 called = []
8489
8590 @context_event
You can’t perform that action at this time.
0 commit comments