scalars: Factor out internal helper methods into top-level functions
@@ -118,10 +118,39 @@ class ScalarType(nodes.Node, constraints.ConsistencySubject,
return False
left = str(self.get_topmost_concrete_base().name)
right = str(other.get_topmost_concrete_base().name)
- return self._is_implicitly_castable_impl(left, right)
+ return _is_implicitly_castable_impl(left, right)
+
+ def find_common_implicitly_castable_type(
+ self, other: s_types.Type,
+ schema) -> typing.Optional[s_types.Type]:
+
+ if not isinstance(other, ScalarType):
+ return
+
+ left = str(self.get_topmost_concrete_base().name)
+ right = str(other.get_topmost_concrete_base().name)
+
+ if left == right:
+ return schema.get(left)
+
+ result = _find_common_castable_type_impl(left, right)
+ if result is not None:
+ return schema.get(result)
+
+
+# source -> target (source can be implicitly casted into target)
+_implicit_numeric_cast_map = {
+ 'std::int16': 'std::int32',
+ 'std::int32': 'std::int64',
+ 'std::int64': 'std::float64',
+ 'std::float32': 'std::float64',
+ 'std::float64': 'std::decimal',
+ 'std::decimal': None
+}
+
@functools.lru_cache()
- def _is_implicitly_castable_impl(self, left: str, right: str) -> bool:
+def _is_implicitly_castable_impl(left: str, right: str) -> bool:
if left == right:
return True
@@ -132,9 +161,10 @@ class ScalarType(nodes.Node, constraints.ConsistencySubject,
if left == right:
return True
+
@functools.lru_cache()
def _find_common_castable_type_impl(
- self, left: str, right: str) -> typing.Optional[str]:
+ left: str, right: str) -> typing.Optional[str]:
if left == right:
return left
@@ -155,34 +185,6 @@ class ScalarType(nodes.Node, constraints.ConsistencySubject,
if left == right:
return left
- def find_common_implicitly_castable_type(
- self, other: s_types.Type,
- schema) -> typing.Optional[s_types.Type]:
-
- if not isinstance(other, ScalarType):
- return
-
- left = str(self.get_topmost_concrete_base().name)
- right = str(other.get_topmost_concrete_base().name)
-
- if left == right:
- return schema.get(left)
-
- result = self._find_common_castable_type_impl(left, right)
- if result is not None:
- return schema.get(result)
-
-
-# source -> target (source can be implicitly casted into target)
-_implicit_numeric_cast_map = {
- 'std::int16': 'std::int32',
- 'std::int32': 'std::int64',
- 'std::int64': 'std::float64',
- 'std::float32': 'std::float64',
- 'std::float64': 'std::decimal',
- 'std::decimal': None
-}
-
class ScalarTypeCommandContext(sd.ObjectCommandContext,
attributes.AttributeSubjectCommandContext,
