@@ -693,8 +693,8 @@ class MyCustomDetail:
693693 timestamp : datetime
694694
695695
696- async def test_application_error_details_with_type_hints ():
697- """Test ApplicationError details with type hints functionality."""
696+ async def test_application_error_get_detail ():
697+ """Test ApplicationError get_detail functionality."""
698698
699699 # Test data
700700 detail_str = "error detail"
@@ -727,16 +727,22 @@ async def test_application_error_details_with_type_hints():
727727 assert details [2 ]["value" ] == 42
728728 assert details [2 ]["timestamp" ] == "2023-01-01T12:00:00"
729729
730- # Test accessing details with type hints
731- typed_details = decoded_error .details_with_type_hints ([str , int , MyCustomDetail ])
732- assert len (typed_details ) == 3
733- assert typed_details [0 ] == detail_str
734- assert typed_details [1 ] == detail_int
730+ # Test accessing individual details with type hints
731+ assert decoded_error .get_detail (0 , str ) == detail_str
732+ assert decoded_error .get_detail (1 , int ) == detail_int
735733 # Custom object is properly reconstructed with type hint
736- assert isinstance (typed_details [2 ], MyCustomDetail )
737- assert typed_details [2 ].name == "test"
738- assert typed_details [2 ].value == 42
739- assert typed_details [2 ].timestamp == datetime (2023 , 1 , 1 , 12 , 0 , 0 )
734+ custom_detail = decoded_error .get_detail (2 , MyCustomDetail )
735+ assert isinstance (custom_detail , MyCustomDetail )
736+ assert custom_detail .name == "test"
737+ assert custom_detail .value == 42
738+ assert custom_detail .timestamp == datetime (2023 , 1 , 1 , 12 , 0 , 0 )
739+
740+ # Test accessing details without type hints using get_detail
741+ assert decoded_error .get_detail (0 ) == detail_str
742+ assert decoded_error .get_detail (1 ) == detail_int
743+ dict_detail = decoded_error .get_detail (2 )
744+ assert isinstance (dict_detail , dict )
745+ assert dict_detail ["name" ] == "test"
740746
741747
742748async def test_application_error_details_empty ():
@@ -751,34 +757,9 @@ async def test_application_error_details_empty():
751757
752758 assert isinstance (decoded_error , ApplicationError )
753759 assert len (decoded_error .details ) == 0
754- assert len (decoded_error .details_with_type_hints ([])) == 0
755-
756-
757- async def test_application_error_details_partial_type_hints ():
758- """Test ApplicationError details with partial type hints."""
759-
760- detail1 = "string detail"
761- detail2 = 456
762- detail3 = MyCustomDetail ("partial" , 99 , datetime (2023 , 6 , 15 , 9 , 30 , 0 ))
763-
764- error = ApplicationError (
765- "Partial hints error" , detail1 , detail2 , detail3 , type = "PartialHints"
766- )
767-
768- failure = Failure ()
769- converter = DataConverter .default
770- await converter .encode_failure (error , failure )
771- decoded_error = await converter .decode_failure (failure )
772-
773- # Provide type hints for only the first two details
774- assert isinstance (decoded_error , ApplicationError )
775- typed_details = decoded_error .details_with_type_hints ([str , int ])
776- assert len (typed_details ) == 3
777- assert typed_details [0 ] == detail1
778- assert typed_details [1 ] == detail2
779- # Third detail has no type hint, so it remains as dict
780- assert isinstance (typed_details [2 ], dict )
781- assert typed_details [2 ]["name" ] == "partial"
760+ # Test get_detail with out of range index
761+ with pytest .raises (IndexError ):
762+ decoded_error .get_detail (0 )
782763
783764
784765async def test_application_error_details_direct_creation ():
@@ -804,13 +785,12 @@ async def test_application_error_details_direct_creation():
804785 assert details [0 ] == detail1
805786 assert isinstance (details [1 ], dict ) # No type hint
806787
807- # Test with type hints
808- typed_details = error .details_with_type_hints ([str , MyCustomDetail ])
809- assert len (typed_details ) == 2
810- assert typed_details [0 ] == detail1
811- assert isinstance (typed_details [1 ], MyCustomDetail )
812- assert typed_details [1 ].name == "direct"
813- assert typed_details [1 ].value == 777
788+ # Test get_detail method
789+ assert error .get_detail (0 , str ) == detail1
790+ custom_detail = error .get_detail (1 , MyCustomDetail )
791+ assert isinstance (custom_detail , MyCustomDetail )
792+ assert custom_detail .name == "direct"
793+ assert custom_detail .value == 777
814794
815795
816796async def test_application_error_details_none_payload_converter ():
@@ -824,10 +804,11 @@ async def test_application_error_details_none_payload_converter():
824804
825805 # Both methods should return the same result - the raw details tuple
826806 details = error .details
827- typed_details = error .details_with_type_hints ([str , int ])
828-
829807 assert details == (detail1 , detail2 )
830- assert typed_details == (detail1 , detail2 )
808+
809+ # Test get_detail method
810+ assert error .get_detail (0 ) == detail1
811+ assert error .get_detail (1 ) == detail2
831812
832813
833814def test_application_error_details_edge_cases ():
@@ -845,7 +826,8 @@ def test_application_error_details_edge_cases():
845826 )
846827
847828 assert len (error .details ) == 0
848- assert len (error .details_with_type_hints ([str ])) == 0
829+ with pytest .raises (IndexError ):
830+ error .get_detail (0 )
849831
850832 # Test with non-Payloads details when payload_converter is set
851833 error2 = ApplicationError (
@@ -856,4 +838,5 @@ def test_application_error_details_edge_cases():
856838
857839 # Should return the raw details since they're not Payloads
858840 assert error2 .details == ("string" , 123 )
859- assert error2 .details_with_type_hints ([str , int ]) == ("string" , 123 )
841+ assert error2 .get_detail (0 ) == "string"
842+ assert error2 .get_detail (1 ) == 123
0 commit comments