60
60
+ ConnectionAcquisitionTimeoutError
61
61
"""
62
62
63
- from __future__ import annotations
63
+ from __future__ import annotations as _
64
64
65
- import typing as t
65
+ import typing as _t
66
66
from copy import deepcopy as _deepcopy
67
67
from enum import Enum as _Enum
68
68
69
69
from ._warnings import preview as _preview
70
70
71
71
72
- if t .TYPE_CHECKING :
73
- from collections .abc import Mapping
72
+ if _t .TYPE_CHECKING :
73
+ from collections .abc import Mapping as _Mapping
74
74
75
- import typing_extensions as te
75
+ import typing_extensions as _te
76
76
77
77
from ._async .work import (
78
- AsyncManagedTransaction ,
79
- AsyncResult ,
80
- AsyncSession ,
81
- AsyncTransaction ,
78
+ AsyncManagedTransaction as _AsyncManagedTransaction ,
79
+ AsyncResult as _AsyncResult ,
80
+ AsyncSession as _AsyncSession ,
81
+ AsyncTransaction as _AsyncTransaction ,
82
82
)
83
83
from ._sync .work import (
84
- ManagedTransaction ,
85
- Result ,
86
- Session ,
87
- Transaction ,
84
+ ManagedTransaction as _ManagedTransaction ,
85
+ Result as _Result ,
86
+ Session as _Session ,
87
+ Transaction as _Transaction ,
88
88
)
89
89
90
- _TTransaction : t .TypeAlias = (
91
- AsyncManagedTransaction
92
- | AsyncTransaction
93
- | ManagedTransaction
94
- | Transaction
90
+ _TTransaction : _t .TypeAlias = (
91
+ _AsyncManagedTransaction
92
+ | _AsyncTransaction
93
+ | _ManagedTransaction
94
+ | _Transaction
95
95
)
96
- _TResult : t .TypeAlias = AsyncResult | Result
97
- _TSession : t .TypeAlias = AsyncSession | Session
98
- _T = t .TypeVar ("_T" )
96
+ _TResult : _t .TypeAlias = _AsyncResult | _Result
97
+ _TSession : _t .TypeAlias = _AsyncSession | _Session
98
+ _T = _t .TypeVar ("_T" )
99
99
100
100
101
101
__all__ = [
138
138
]
139
139
140
140
141
- _CLASSIFICATION_CLIENT : te .Final [str ] = "ClientError"
142
- _CLASSIFICATION_TRANSIENT : te .Final [str ] = "TransientError"
143
- _CLASSIFICATION_DATABASE : te .Final [str ] = "DatabaseError"
141
+ _CLASSIFICATION_CLIENT : _te .Final [str ] = "ClientError"
142
+ _CLASSIFICATION_TRANSIENT : _te .Final [str ] = "TransientError"
143
+ _CLASSIFICATION_DATABASE : _te .Final [str ] = "DatabaseError"
144
144
145
145
146
146
_ERROR_REWRITE_MAP : dict [str , tuple [str , str | None ]] = {
167
167
}
168
168
169
169
170
- _UNKNOWN_NEO4J_CODE : te .Final [str ] = "Neo.DatabaseError.General.UnknownError"
170
+ _UNKNOWN_NEO4J_CODE : _te .Final [str ] = "Neo.DatabaseError.General.UnknownError"
171
171
# TODO: 7.0 - Make _UNKNOWN_GQL_MESSAGE the default message
172
- _UNKNOWN_MESSAGE : te .Final [str ] = "An unknown error occurred"
173
- _UNKNOWN_GQL_STATUS : te .Final [str ] = "50N42"
174
- _UNKNOWN_GQL_DESCRIPTION : te .Final [str ] = (
172
+ _UNKNOWN_MESSAGE : _te .Final [str ] = "An unknown error occurred"
173
+ _UNKNOWN_GQL_STATUS : _te .Final [str ] = "50N42"
174
+ _UNKNOWN_GQL_DESCRIPTION : _te .Final [str ] = (
175
175
"error: general processing exception - unexpected error"
176
176
)
177
- _UNKNOWN_GQL_MESSAGE : te .Final [str ] = (
177
+ _UNKNOWN_GQL_MESSAGE : _te .Final [str ] = (
178
178
f"{ _UNKNOWN_GQL_STATUS } : "
179
179
"Unexpected error has occurred. See debug log for details."
180
180
)
181
- _UNKNOWN_GQL_DIAGNOSTIC_RECORD : te .Final [tuple [tuple [str , t .Any ], ...]] = (
181
+ _UNKNOWN_GQL_DIAGNOSTIC_RECORD : _te .Final [tuple [tuple [str , _t .Any ], ...]] = (
182
182
("OPERATION" , "" ),
183
183
("OPERATION_CODE" , "0" ),
184
184
("CURRENT_SCHEMA" , "/" ),
@@ -240,12 +240,12 @@ class GqlError(Exception):
240
240
_gql_status_description : str
241
241
_gql_raw_classification : str | None
242
242
_gql_classification : GqlErrorClassification
243
- _status_diagnostic_record : dict [str , t .Any ] # original, internal only
244
- _diagnostic_record : dict [str , t .Any ] # copy to be used externally
243
+ _status_diagnostic_record : dict [str , _t .Any ] # original, internal only
244
+ _diagnostic_record : dict [str , _t .Any ] # copy to be used externally
245
245
_gql_cause : GqlError | None
246
246
247
247
@staticmethod
248
- def _hydrate_cause (** metadata : t .Any ) -> GqlError :
248
+ def _hydrate_cause (** metadata : _t .Any ) -> GqlError :
249
249
meta_extractor = _MetaExtractor (metadata )
250
250
gql_status = meta_extractor .str_value ("gql_status" )
251
251
description = meta_extractor .str_value ("description" )
@@ -276,7 +276,7 @@ def _init_gql(
276
276
gql_status : str ,
277
277
message : str ,
278
278
description : str ,
279
- diagnostic_record : dict [str , t .Any ] | None = None ,
279
+ diagnostic_record : dict [str , _t .Any ] | None = None ,
280
280
cause : GqlError | None = None ,
281
281
) -> None :
282
282
self ._gql_status = gql_status
@@ -438,7 +438,7 @@ def _gql_classification_no_preview(self) -> GqlErrorClassification:
438
438
if not (
439
439
isinstance (classification , str )
440
440
and classification
441
- in t .cast (t .Iterable [str ], iter (GqlErrorClassification ))
441
+ in _t .cast (_t .Iterable [str ], iter (GqlErrorClassification ))
442
442
):
443
443
self ._gql_classification = GqlErrorClassification .UNKNOWN
444
444
else :
@@ -450,15 +450,15 @@ def _gql_classification_no_preview(self) -> GqlErrorClassification:
450
450
def gql_classification (self ) -> GqlErrorClassification :
451
451
return self ._gql_classification_no_preview
452
452
453
- def _get_status_diagnostic_record (self ) -> dict [str , t .Any ]:
453
+ def _get_status_diagnostic_record (self ) -> dict [str , _t .Any ]:
454
454
if hasattr (self , "_status_diagnostic_record" ):
455
455
return self ._status_diagnostic_record
456
456
457
457
self ._status_diagnostic_record = dict (_UNKNOWN_GQL_DIAGNOSTIC_RECORD )
458
458
return self ._status_diagnostic_record
459
459
460
460
@property
461
- def _diagnostic_record_no_preview (self ) -> Mapping [str , t .Any ]:
461
+ def _diagnostic_record_no_preview (self ) -> _Mapping [str , _t .Any ]:
462
462
if hasattr (self , "_diagnostic_record" ):
463
463
return self ._diagnostic_record
464
464
@@ -469,7 +469,7 @@ def _diagnostic_record_no_preview(self) -> Mapping[str, t.Any]:
469
469
470
470
@property
471
471
@_preview ("GQLSTATUS support is a preview feature." )
472
- def diagnostic_record (self ) -> Mapping [str , t .Any ]:
472
+ def diagnostic_record (self ) -> _Mapping [str , _t .Any ]:
473
473
return self ._diagnostic_record_no_preview
474
474
475
475
def __str__ (self ):
@@ -493,7 +493,7 @@ class Neo4jError(GqlError):
493
493
_category : str
494
494
_title : str
495
495
#: (dict) Any additional information returned by the server.
496
- _metadata : dict [str , t .Any ]
496
+ _metadata : dict [str , _t .Any ]
497
497
_from_server : bool
498
498
499
499
_retryable = False
@@ -508,7 +508,7 @@ def __init__(self, *args: object) -> None:
508
508
)
509
509
510
510
@staticmethod
511
- def _hydrate_neo4j (** metadata : t .Any ) -> Neo4jError :
511
+ def _hydrate_neo4j (** metadata : _t .Any ) -> Neo4jError :
512
512
meta_extractor = _MetaExtractor (metadata )
513
513
code = meta_extractor .str_value ("code" ) or _UNKNOWN_NEO4J_CODE
514
514
message = meta_extractor .str_value ("message" ) or _UNKNOWN_MESSAGE
@@ -525,7 +525,7 @@ def _hydrate_neo4j(**metadata: t.Any) -> Neo4jError:
525
525
return inst
526
526
527
527
@staticmethod
528
- def _hydrate_gql (** metadata : t .Any ) -> Neo4jError :
528
+ def _hydrate_gql (** metadata : _t .Any ) -> Neo4jError :
529
529
meta_extractor = _MetaExtractor (metadata )
530
530
gql_status = meta_extractor .str_value ("gql_status" )
531
531
status_description = meta_extractor .str_value ("description" )
@@ -643,7 +643,7 @@ def title(self) -> str:
643
643
return self ._title
644
644
645
645
@property
646
- def metadata (self ) -> dict [str , t .Any ]:
646
+ def metadata (self ) -> dict [str , _t .Any ]:
647
647
# Undocumented, might be useful for debugging
648
648
return self ._metadata
649
649
@@ -709,16 +709,16 @@ def __str__(self):
709
709
710
710
711
711
class _MetaExtractor :
712
- def __init__ (self , metadata : dict [str , t .Any ]) -> None :
712
+ def __init__ (self , metadata : dict [str , _t .Any ]) -> None :
713
713
self ._metadata = metadata
714
714
715
- def rest (self ) -> dict [str , t .Any ]:
715
+ def rest (self ) -> dict [str , _t .Any ]:
716
716
return self ._metadata
717
717
718
- @t .overload
718
+ @_t .overload
719
719
def str_value (self , key : str ) -> str | None : ...
720
720
721
- @t .overload
721
+ @_t .overload
722
722
def str_value (self , key : str , default : _T ) -> str | _T : ...
723
723
724
724
def str_value (
@@ -729,15 +729,15 @@ def str_value(
729
729
res = default
730
730
return res
731
731
732
- @t .overload
733
- def map_value (self , key : str ) -> dict [str , t .Any ] | None : ...
732
+ @_t .overload
733
+ def map_value (self , key : str ) -> dict [str , _t .Any ] | None : ...
734
734
735
- @t .overload
736
- def map_value (self , key : str , default : _T ) -> dict [str , t .Any ] | _T : ...
735
+ @_t .overload
736
+ def map_value (self , key : str , default : _T ) -> dict [str , _t .Any ] | _T : ...
737
737
738
738
def map_value (
739
739
self , key : str , default : _T | None = None
740
- ) -> dict [str , t .Any ] | _T | None :
740
+ ) -> dict [str , _t .Any ] | _T | None :
741
741
res = self ._metadata .pop (key , default )
742
742
if not (
743
743
isinstance (res , dict ) and all (isinstance (k , str ) for k in res )
0 commit comments