enhance generic_repr to cascade down superclasses

Issue #2893 resolved
Mike Bayer repo owner created an issue

if we make MySQL's _String do this:

class _StringType(sqltypes.String):
    """Base for MySQL string types."""

    def __repr__(self):
        return util.generic_repr(self,
                                 to_inspect=_StringType)

now we lose "length", unless we add it to additional_kw. This is silly, the to_inspect attribute of generic_repr should accept a list of classes, which we can assume propagates using kw.

Comments (4)

  1. Mike Bayer reporter

    tests we can add when this works:

    diff --git a/test/dialect/mysql/test_types.py b/test/dialect/mysql/test_types.py
    index 071b844..fecf64e 100644
    --- a/test/dialect/mysql/test_types.py
    +++ b/test/dialect/mysql/test_types.py
    @@ -142,8 +142,14 @@ class TypesTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL):
                ]
    
             for type_, args, kw, res in columns:
    +            type_inst = type_(*args, **kw)
                 self.assert_compile(
    -                type_(*args, **kw),
    +                type_inst,
    +                res
    +            )
    +            repr_type = eval(repr(type_inst))
    +            self.assert_compile(
    +                repr_type,
                     res
                 )
    
    @@ -239,8 +245,14 @@ class TypesTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL):
                ]
    
             for type_, args, kw, res in columns:
    +            type_inst = type_(*args, **kw)
    +            self.assert_compile(
    +                type_inst,
    +                res
    +            )
    +            repr_type = eval(repr(type_inst))
                 self.assert_compile(
    -                type_(*args, **kw),
    +                repr_type,
                     res
                 )
    
  2. Log in to comment