Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 8963e19

Browse files
committed
Fix PR issues
1 parent 681a605 commit 8963e19

22 files changed

+117
-210
lines changed

dependencies/vaticle/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ def vaticle_typedb_driver_java():
6767
git_repository(
6868
name = "vaticle_typedb_driver_java",
6969
remote = "https://github.com/dmikhalin/typedb-client-java",
70-
commit = "c1e6d52fe03f16401edc0768a59589a993ad9854" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_factory_tracing
70+
commit = "f2b324aae5202ca28ce9d528f1439b9ba6ffe7ec" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_factory_tracing
7171
)

tests/behaviour/typeql/typeql_steps.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def step_impl(context: Context):
4444
@step("typeql define; throws exception containing \"{pattern}\"")
4545
def step_impl(context: Context, pattern: str):
4646
assert_that(calling(context.tx().query.define).with_args(query=context.text),
47-
raises(Exception, re.escape(pattern)))
47+
raises(TypeDBClientException, re.escape(pattern)))
4848

4949

5050
@step("typeql undefine")
@@ -60,7 +60,7 @@ def step_impl(context: Context):
6060
@step("typeql undefine; throws exception containing \"{pattern}\"")
6161
def step_impl(context: Context, pattern: str):
6262
assert_that(calling(context.tx().query.undefine).with_args(query=context.text),
63-
raises(Exception, re.escape(pattern)))
63+
raises(TypeDBClientException, re.escape(pattern)))
6464

6565

6666
@step("typeql insert")
@@ -76,7 +76,7 @@ def step_impl(context: Context):
7676
@step("typeql insert; throws exception containing \"{pattern}\"")
7777
def step_impl(context: Context, pattern: str):
7878
assert_that(calling(next).with_args(context.tx().query.insert(query=context.text)),
79-
raises(Exception, re.escape(pattern)))
79+
raises(TypeDBClientException, re.escape(pattern)))
8080

8181

8282
@step("typeql delete")
@@ -92,7 +92,7 @@ def step_impl(context: Context):
9292
@step("typeql delete; throws exception containing \"{pattern}\"")
9393
def step_impl(context: Context, pattern: str):
9494
assert_that(calling(context.tx().query.delete).with_args(query=context.text),
95-
raises(Exception, re.escape(pattern)))
95+
raises(TypeDBClientException, re.escape(pattern)))
9696

9797

9898
@step("typeql update")
@@ -108,7 +108,7 @@ def step_impl(context: Context):
108108
@step("typeql update; throws exception containing \"{pattern}\"")
109109
def step_impl(context: Context, pattern: str):
110110
assert_that(calling(next).with_args(context.tx().query.update(query=context.text)),
111-
raises(Exception, re.escape(pattern)))
111+
raises(TypeDBClientException, re.escape(pattern)))
112112

113113

114114
@step("get answers of typeql insert")
@@ -131,7 +131,7 @@ def step_impl(context: Context):
131131
@step("typeql match; throws exception containing \"{pattern}\"")
132132
def step_impl(context: Context, pattern: str):
133133
assert_that(calling(next).with_args(context.tx().query.match(query=context.text)),
134-
raises(Exception, re.escape(pattern)))
134+
raises(TypeDBClientException, re.escape(pattern)))
135135

136136

137137
@step("get answer of typeql match aggregate")

typedb/api/connection/credential.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@
2121

2222
from typing import Optional
2323

24-
from typedb.native_client_wrapper import credential_new
24+
from typedb.native_client_wrapper import credential_new, Credential as NativeCredential
2525

26-
from typedb.common.exception import TypeDBClientExceptionExt, CLUSTER_CREDENTIAL_INCONSISTENT
26+
from typedb.common.exception import TypeDBClientExceptionExt, CLUSTER_CREDENTIAL_INCONSISTENT, ILLEGAL_STATE
27+
from typedb.common.native_wrapper import NativeWrapper
2728

2829

29-
class TypeDBCredential:
30+
class TypeDBCredential(NativeWrapper[NativeCredential]):
3031

3132
def __init__(self, username: str, password: str, *, tls_root_ca_path: Optional[str] = None,
3233
tls_enabled: bool = True):
3334
if tls_root_ca_path is not None and not tls_enabled:
3435
raise TypeDBClientExceptionExt.of(CLUSTER_CREDENTIAL_INCONSISTENT)
35-
self._native_object = credential_new(username, password, tls_root_ca_path, tls_enabled)
36+
super().__init__(credential_new(username, password, tls_root_ca_path, tls_enabled))
3637

3738
@property
38-
def native_object(self):
39-
return self._native_object
39+
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:
40+
return TypeDBClientExceptionExt.of(ILLEGAL_STATE)

typedb/api/connection/options.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
options_has_transaction_timeout_millis, options_get_transaction_timeout_millis, \
3333
options_set_transaction_timeout_millis, options_get_schema_lock_acquire_timeout_millis, \
3434
options_has_schema_lock_acquire_timeout_millis, options_set_schema_lock_acquire_timeout_millis, \
35-
options_set_read_any_replica, options_get_read_any_replica, options_has_read_any_replica
35+
options_set_read_any_replica, options_get_read_any_replica, options_has_read_any_replica, Options as NativeOptions
3636

37-
from typedb.common.exception import TypeDBClientExceptionExt, POSITIVE_VALUE_REQUIRED
37+
from typedb.common.exception import TypeDBClientExceptionExt, ILLEGAL_STATE, POSITIVE_VALUE_REQUIRED
38+
from typedb.common.native_wrapper import NativeWrapper
3839

3940

40-
class TypeDBOptions:
41+
class TypeDBOptions(NativeWrapper[NativeOptions]):
4142

4243
def __init__(self, *,
4344
infer: Optional[bool] = None,
@@ -51,7 +52,7 @@ def __init__(self, *,
5152
schema_lock_acquire_timeout_millis: Optional[int] = None,
5253
read_any_replica: Optional[bool] = None,
5354
):
54-
self._native_object = options_new()
55+
super().__init__(options_new())
5556
if infer is not None:
5657
self.infer = infer
5758
if trace_inference is not None:
@@ -74,8 +75,8 @@ def __init__(self, *,
7475
self.read_any_replica = read_any_replica
7576

7677
@property
77-
def native_object(self):
78-
return self._native_object
78+
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:
79+
return TypeDBClientExceptionExt.of(ILLEGAL_STATE)
7980

8081
@property
8182
def infer(self) -> Optional[bool]:

typedb/common/native_object_mixin.py renamed to typedb/common/native_wrapper.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
from __future__ import annotations
2323

2424
from abc import ABC, abstractmethod
25-
from typing import Any
25+
from typing import Any, Generic, TypeVar
2626

2727
from typedb.common.exception import TypeDBClientExceptionExt
2828

2929

30-
class NativeObjectMixin(ABC):
30+
T = TypeVar("T")
3131

32-
@property
33-
@abstractmethod
34-
def _native_object(self) -> Any:
35-
pass
32+
33+
class NativeWrapper(ABC, Generic[T]):
34+
35+
def __init__(self, native_object: T):
36+
self._native_object = native_object
3637

3738
@property
3839
@abstractmethod

typedb/concept/answer/concept_map.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,18 @@
2828
explainables_get_relation, explainables_get_attribute, explainables_get_ownership, \
2929
explainables_get_relations_keys, explainables_get_attributes_keys, explainables_get_ownerships_keys, \
3030
string_pair_iterator_next, explainables_to_string, explainables_equals, explainable_get_conjunction, \
31-
explainable_get_id
31+
explainable_get_id, ConceptMap as NativeConceptMap, Explainables as NativeExplainables, \
32+
Explainable as NativeExplainable
3233

3334
from typedb.api.answer.concept_map import ConceptMap
3435
from typedb.common.exception import TypeDBClientExceptionExt, ILLEGAL_STATE, MISSING_VARIABLE, \
3536
NONEXISTENT_EXPLAINABLE_CONCEPT, NONEXISTENT_EXPLAINABLE_OWNERSHIP, NULL_NATIVE_OBJECT, VARIABLE_DOES_NOT_EXIST
3637
from typedb.common.iterator_wrapper import IteratorWrapper
37-
from typedb.common.native_object_mixin import NativeObjectMixin
38+
from typedb.common.native_wrapper import NativeWrapper
3839
from typedb.concept import concept_factory
3940

4041
if TYPE_CHECKING:
4142
from typedb.api.concept.concept import Concept
42-
from typedb.native_client_wrapper import ConceptMap as NativeConceptMap, Explainables as NativeExplainables, \
43-
Explainable as NativeExplainable
4443

4544

4645
def _not_blank_var(var: str) -> str:
@@ -49,16 +48,12 @@ def _not_blank_var(var: str) -> str:
4948
return var
5049

5150

52-
class _ConceptMap(ConceptMap, NativeObjectMixin):
51+
class _ConceptMap(ConceptMap, NativeWrapper[NativeConceptMap]):
5352

5453
def __init__(self, concept_map: NativeConceptMap):
5554
if not concept_map:
5655
raise TypeDBClientExceptionExt(NULL_NATIVE_OBJECT)
57-
self.__native_object = concept_map
58-
59-
@property
60-
def _native_object(self) -> NativeConceptMap:
61-
return self.__native_object
56+
super().__init__(concept_map)
6257

6358
@property
6459
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:
@@ -93,16 +88,12 @@ def __eq__(self, other):
9388
def __hash__(self):
9489
return hash((tuple(self.variables()), tuple(self.concepts())))
9590

96-
class Explainables(ConceptMap.Explainables, NativeObjectMixin):
91+
class Explainables(ConceptMap.Explainables, NativeWrapper[NativeExplainables]):
9792

9893
def __init__(self, explainables: NativeExplainables):
9994
if not explainables:
10095
raise TypeDBClientExceptionExt(NULL_NATIVE_OBJECT)
101-
self.__native_object = explainables
102-
103-
@property
104-
def _native_object(self) -> NativeExplainables:
105-
return self.__native_object
96+
super().__init__(explainables)
10697

10798
@property
10899
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:
@@ -154,16 +145,12 @@ def __eq__(self, other):
154145
def __hash__(self):
155146
return hash((tuple(self.relations()), tuple(self.attributes()), tuple(self.ownerships())))
156147

157-
class Explainable(ConceptMap.Explainable, NativeObjectMixin):
148+
class Explainable(ConceptMap.Explainable, NativeWrapper[NativeExplainable]):
158149

159150
def __init__(self, explainable: NativeExplainable):
160151
if not explainable:
161152
raise TypeDBClientExceptionExt(NULL_NATIVE_OBJECT)
162-
self.__native_object = explainable
163-
164-
@property
165-
def _native_object(self) -> NativeExplainable:
166-
return self.__native_object
153+
super().__init__(explainable)
167154

168155
@property
169156
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:

typedb/concept/answer/concept_map_group.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,27 @@
2424
from typing import Iterator, TYPE_CHECKING
2525

2626
from typedb.native_client_wrapper import concept_map_group_get_owner, concept_map_group_get_concept_maps, \
27-
concept_map_iterator_next, concept_map_group_to_string, concept_map_group_equals
27+
concept_map_iterator_next, concept_map_group_to_string, concept_map_group_equals, \
28+
ConceptMapGroup as NativeConceptMapGroup
2829

2930
from typedb.api.answer.concept_map_group import ConceptMapGroup
3031
from typedb.common.exception import TypeDBClientExceptionExt, ILLEGAL_STATE, NULL_NATIVE_OBJECT
3132
from typedb.common.iterator_wrapper import IteratorWrapper
32-
from typedb.common.native_object_mixin import NativeObjectMixin
33+
from typedb.common.native_wrapper import NativeWrapper
3334
from typedb.concept import concept_factory
3435
from typedb.concept.answer.concept_map import _ConceptMap
3536

3637
if TYPE_CHECKING:
3738
from typedb.api.concept.concept import Concept
3839
from typedb.api.answer.concept_map import ConceptMap
39-
from typedb.native_client_wrapper import ConceptMapGroup as NativeConceptMapGroup
4040

4141

42-
class _ConceptMapGroup(ConceptMapGroup, NativeObjectMixin):
42+
class _ConceptMapGroup(ConceptMapGroup, NativeWrapper[NativeConceptMapGroup]):
4343

4444
def __init__(self, concept_map_group: NativeConceptMapGroup):
4545
if not concept_map_group:
4646
raise TypeDBClientExceptionExt(NULL_NATIVE_OBJECT)
47-
self.__native_object = concept_map_group
48-
49-
@property
50-
def _native_object(self) -> NativeConceptMapGroup:
51-
return self.__native_object
47+
super().__init__(concept_map_group)
5248

5349
@property
5450
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:

typedb/concept/answer/numeric.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,20 @@
2121

2222
from __future__ import annotations
2323

24-
from typing import TYPE_CHECKING
25-
2624
from typedb.native_client_wrapper import numeric_is_long, numeric_is_double, numeric_is_nan, \
27-
numeric_get_long, numeric_get_double, numeric_to_string
25+
numeric_get_long, numeric_get_double, numeric_to_string, Numeric as NativeNumeric
2826

2927
from typedb.api.answer.numeric import Numeric
3028
from typedb.common.exception import TypeDBClientExceptionExt, ILLEGAL_CAST, ILLEGAL_STATE, NULL_NATIVE_OBJECT
31-
from typedb.common.native_object_mixin import NativeObjectMixin
32-
33-
if TYPE_CHECKING:
34-
from typedb.native_client_wrapper import Numeric as NativeNumeric
29+
from typedb.common.native_wrapper import NativeWrapper
3530

3631

37-
class _Numeric(Numeric, NativeObjectMixin):
32+
class _Numeric(Numeric, NativeWrapper[NativeNumeric]):
3833

3934
def __init__(self, numeric: NativeNumeric):
4035
if not numeric:
4136
raise TypeDBClientExceptionExt(NULL_NATIVE_OBJECT)
42-
self.__native_object = numeric
43-
44-
@property
45-
def _native_object(self) -> NativeNumeric:
46-
return self.__native_object
37+
super().__init__(numeric)
4738

4839
@property
4940
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:

typedb/concept/answer/numeric_group.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,26 @@
2323

2424
from typing import TYPE_CHECKING
2525

26-
from typedb.native_client_wrapper import numeric_group_get_owner, \
27-
numeric_group_get_numeric, numeric_group_to_string, numeric_group_equals
26+
from typedb.native_client_wrapper import numeric_group_get_owner, numeric_group_get_numeric, \
27+
numeric_group_to_string, numeric_group_equals, NumericGroup as NativeNumericGroup
2828

2929
from typedb.api.answer.numeric_group import NumericGroup
3030
from typedb.common.exception import TypeDBClientExceptionExt, NULL_NATIVE_OBJECT, ILLEGAL_STATE
31-
from typedb.common.native_object_mixin import NativeObjectMixin
31+
from typedb.common.native_wrapper import NativeWrapper
3232
from typedb.concept import concept_factory
3333
from typedb.concept.answer.numeric import _Numeric
3434

3535
if TYPE_CHECKING:
3636
from typedb.api.answer.numeric import Numeric
3737
from typedb.api.concept.concept import Concept
38-
from typedb.native_client_wrapper import NumericGroup as NativeNumericGroup
3938

4039

41-
class _NumericGroup(NumericGroup, NativeObjectMixin):
40+
class _NumericGroup(NumericGroup, NativeWrapper[NativeNumericGroup]):
4241

4342
def __init__(self, numeric_group: NativeNumericGroup):
4443
if not numeric_group:
4544
raise TypeDBClientExceptionExt(NULL_NATIVE_OBJECT)
46-
self.__native_object = numeric_group
47-
48-
@property
49-
def _native_object(self) -> NativeNumericGroup:
50-
return self.__native_object
45+
super().__init__(numeric_group)
5146

5247
@property
5348
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:

typedb/concept/concept.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,20 @@
2222
from __future__ import annotations
2323

2424
from abc import ABC, abstractmethod
25-
from typing import TYPE_CHECKING
2625

27-
from typedb.native_client_wrapper import concept_to_string, concept_equals
26+
from typedb.native_client_wrapper import concept_to_string, concept_equals, Concept as NativeConcept
2827

2928
from typedb.api.concept.concept import Concept
3029
from typedb.common.exception import TypeDBClientExceptionExt, ILLEGAL_STATE, NULL_NATIVE_OBJECT
31-
from typedb.common.native_object_mixin import NativeObjectMixin
30+
from typedb.common.native_wrapper import NativeWrapper
3231

33-
if TYPE_CHECKING:
34-
from typedb.native_client_wrapper import Concept as NativeConcept
3532

36-
37-
class _Concept(Concept, NativeObjectMixin, ABC):
33+
class _Concept(Concept, NativeWrapper[NativeConcept], ABC):
3834

3935
def __init__(self, concept: NativeConcept):
4036
if not concept:
4137
raise TypeDBClientExceptionExt(NULL_NATIVE_OBJECT)
42-
self.__native_object = concept
43-
44-
@property
45-
def _native_object(self) -> NativeConcept:
46-
return self.__native_object
38+
super().__init__(concept)
4739

4840
@property
4941
def _native_object_not_owned_exception(self) -> TypeDBClientExceptionExt:

0 commit comments

Comments
 (0)