self._default_length = length = 0
if length_arg is not NO_ARG:
- if not _disable_warnings and length_arg < length:
+ if (
+ not _disable_warnings
+ and length_arg is not None
+ and length_arg < length
+ ):
raise ValueError(
"When provided, length must be larger or equal"
" than the length of the longest enum value. %s < %s"
)
def as_generic(self, allow_nulltype=False):
- if hasattr(self, "enums"):
+ try:
args = self.enums
- else:
+ except AttributeError:
raise NotImplementedError(
"TypeEngine.as_generic() heuristic "
"is undefined for types that inherit Enum but do not have "
"an `enums` attribute."
- )
+ ) from None
return util.constructor_copy(
self, self._generic_type_affinity, *args, _disable_warnings=True
e = Enum("x", "y", "long", native_enum=False, length=42)
eq_(e.length, 42)
+ def test_none_length_non_native(self):
+ e = Enum("x", "y", native_enum=False, length=None)
+ eq_(e.length, None)
+ eq_(repr(e), "Enum('x', 'y', native_enum=False, length=None)")
+ self.assert_compile(e, "VARCHAR", dialect="default")
+
def test_omit_aliases(self, connection):
table0 = self.tables["stdlib_enum_table"]
type0 = table0.c.someenum.type