Changeset 970


Ignore:
Timestamp:
Apr 19, 2019, 9:39:56 AM (4 months ago)
Author:
cito
Message:

Avoid raising AttributeError?

This might be slightly better in Python 3.
Also, handle the case when an AttributeError? is raised
inside the pg_repr or pg_str method.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pg.py

    r969 r970  
    545545            else:
    546546                typ = simple = self.guess_simple_type(value) or 'text'
    547             try:
    548                 value = value.__pg_str__(typ)
    549             except AttributeError:
    550                 pass
     547            pg_str = getattr(value, '__pg_str__', None)
     548            if pg_str:
     549                value = pg_str(typ)
    551550            if simple == 'text':
    552551                pass
     
    660659            q = self.adapt_inline
    661660            return '(%s)' % ','.join(str(q(v)) for v in value)
    662         try:
    663             value = value.__pg_repr__()
    664         except AttributeError:
     661        pg_repr = getattr(value, '__pg_repr__', None)
     662        if not pg_repr:
    665663            raise InterfaceError(
    666664                'Do not know how to adapt type %s' % type(value))
     665        value = pg_repr()
    667666        if isinstance(value, (tuple, list)):
    668667            value = self.adapt_inline(value)
Note: See TracChangeset for help on using the changeset viewer.