Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Filter chaining with properties #54

Closed
numberoverzero opened this issue Aug 6, 2016 · 1 comment
Closed

Replace Filter chaining with properties #54

numberoverzero opened this issue Aug 6, 2016 · 1 comment
Assignees
Labels
Milestone

Comments

@numberoverzero
Copy link
Owner

Continuing to write more docs, the chaining syntax isn't nearly as comfortable as in other languages. This is mainly because of the lack of implicit continuation. Instead of fighting that with explicit continuation or wrapping parentheses, it's probably better to work with Python than try to shoehorn C#-like LINQ in.

Once again pulling inspiration from Requests, Session configuration saw a change in 1.0[source] from init kwargs to attributes:

# pre-1.0
params = {'hello': 'world'}
s = requests.session(params=params)

#1.0+
params = {'hello': 'world'}
s = requests.session()
s.params = params

Filter wouldn't be considering exactly the same change, but it's a similar syntax cleanup.

Here's the current options with 0.9.12:

#0.9.12 single line
query = engine.query(Model).key(Model.id == "foo").filter(Model.expires_after < arrow.now())

#0.9.12 wrapped in parens
query = (
    engine
    .query(Model)
    .key(Model.id == "foo")
    .filter(Model.expires_after < arrow.now())
)

#0.9.12 explicit line continuation
query = engine.query(Model) \
    .key(Model.id == "foo") \
    .filter(Model.expires_after < arrow.now())

#0.9.12 individual chaining
query = engine.query(Model)
query = query.key(Model.id == "foo")
query = query.filter(Model.expires_after < arrow.now())

#0.9.12 implicit side-effects
query = engine.query(Model)
query.key(Model.id == "foo")
query.filter(Model.expires_after < arrow.now())

As we move down the list, we're almost getting to simply setting attributes on the Filter.

Here's the proposal for 1.0:

# proposed 1.0
query = engine.query(Model)
query.key = Model.id == "foo"
query.filter = Model.expires_after < arrow.now()

This also nicely clears up the filter chaining ambiguity from #43, #44. Early validation can still be done on each setter, but it may be easier to simply check on build (again pulling from Requests: this would be similar to the Request vs PreparedRequest split)

Open question: are attributes validated on set, or on build?

@numberoverzero numberoverzero added this to the 1.0 milestone Aug 6, 2016
@numberoverzero numberoverzero self-assigned this Aug 6, 2016
@numberoverzero
Copy link
Owner Author

numberoverzero commented Aug 7, 2016

  • bloop.filter.Filter
  • tests/
  • README
  • docs/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant