Skip to content

Allow to subclass a Field #2470

Closed
dnozay wants to merge 12 commits intoencode:masterfrom
dnozay:patch-3
Closed

Allow to subclass a Field #2470
dnozay wants to merge 12 commits intoencode:masterfrom
dnozay:patch-3

Conversation

@dnozay
Copy link

@dnozay dnozay commented Jan 26, 2015

Rather than subclass a Field and override init you may want a more data-driven approach where the defaults for read_only, write_only and allow_null are specified on the class.

This is same as #2254 but without the extra commit that is gone to the PR #2469

@dnozay
Copy link
Author

dnozay commented Jan 26, 2015

build failed because of unrelated installation problem.

@lovelydinosaur
Copy link
Contributor

This is certainly less contentious than before - although I'm still somewhat conflicted.

The declarative style is absolutely more graceful, but we're also introducing extra state which makes it more complicated to determine the behavior (eg you need to figure out if .min_length or .validators is used to enforce the validation, whereas previously the min_length was a local variable constrained to the init scope).

There's also some consideration to be given to if we should be using kwargs, or explicit __init__ kwargs throughout. Currently we're not being consistent, but I'd probably prefer the later as it serves as good documentation.

There's also a potential conflict here with #2473 which would suggest that for any api settings based stuff that we probably shouldn't be declaring them as class attributes (which we currently do) which would run in the other direction to the style here.

I'm not sure what the right answer is here.

One thing that it does help clarify to me is that It looks like we should probably be using explicit keyword arguments through (ie stop using kwargs.pop, and always list extra allowable keyword arguments in the init, as a form of declaration.)

@lovelydinosaur
Copy link
Contributor

Closing this off in it's current state - too wide ranging.

Am sympathetic to the intent, but if anyone wants to pull things in this direction I'd suggest by starting with a pull request with a smaller change footprint.

For example make this change for max_length/min_length/max_value/min_value values only, and leave everything else as-is. That'd make for a much more easily reviewable PR, and easier to properly discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants