Ticket #446 (assigned enhancement)

Opened 4 years ago

Last modified 4 years ago

introspection rules could accept callable for more flexibility

Reported by: carl@… Owned by: carl@…
Priority: minor Milestone: 1.0
Component: databaseapi Version: 0.7
Keywords: Cc:


Where the introspection rules currently require a Field attribute name (with magically-handled dots), a callable could be accepted that takes the Field instance as its only argument and returns the parameter value to use. This would allow for much more flexible handling, without a profusion of special-case options in the options dict; including simple things that are impossible now, like correct handling of a boolean Field attribute that is stored as the inverse of the parameter passed in to the Field's init method.

This wouldn't need to affect backwards-compatibility, as the first tuple element can be asked if it is callable(); if not, it will be treated as it is currently.

I will provide a patch with tests, if the idea is accepted in principle.

(In the long run, IMO it'd be more Pythonic if all introspection rules were done this way; you could get rid of the "is_value" special-case option in favor of a simple "lambda f: 'the_value'"; normal attribute access could just be "lambda f: f.attr"; etc.)

Change History

comment:1 Changed 4 years ago by andrew

  • Owner changed from andrew to carl@…
  • Status changed from new to assigned
  • Milestone set to 0.7.1

Yes, I like this idea - option was very simple initially, but it's grown a bit too much.

If you're going to write the patch then I think the best solution is to have the tuple entirely replaced with the callable, and have the callable raise IsDefault? if it doesn't want to show that attribute (that should propagate out correctly into the introspector code).

comment:2 Changed 4 years ago by andrew

  • Milestone changed from 0.7.1 to 0.7.2

comment:3 Changed 4 years ago by andrew

  • Milestone changed from 0.7.2 to 0.7.3

comment:4 Changed 4 years ago by andrew

  • Milestone changed from 0.7.3 to 1.0
Note: See TracTickets for help on using tickets.