-
Notifications
You must be signed in to change notification settings - Fork 49
Add a for_ operator
#887
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
Add a for_ operator
#887
Conversation
| # SPDX-FileCopyrightText: Copyright Gel Data Inc. and the contributors. | ||
|
|
||
|
|
||
| """Query building constructs""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for this to be public? If not, move this into _internal._qbmodel._abstract
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of felt that language features like this ought to be accessible somewhere other than the mildly-hacky std. Not sure if gel.qb is the best for that, though anyway.
I don't really mind dropping it if you think it's not worth exposing
gel/qb.py
Outdated
| _X = TypeVar("_X", bound=_abstract.GelType) | ||
|
|
||
|
|
||
| def for_in(iter: type[_T], body: Callable[[type[_T]], type[_X]]) -> type[_X]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had a bikeshed about naming this and IIRC the conclusion was that for_ was acceptable (we already have and_ and if_ etc).
|
|
||
| def process(self, mod: IntrospectedModule) -> None: | ||
| if str(self.canonical_modpath) == 'std': | ||
| self.write("# Re-export top-level query-builder functions") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You must self.py_file.export(name) and self.py_file.update_globals(names) here (I'd also move this block into prepare_namespace since it already has std-specific wrangling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does that accomplish here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to emitting the explicit export?
dnwpark
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but will wait on those other pydantic comments from elvis
| "PIE", # flake8-pie | ||
| "PL", # pylint | ||
| "PYI", # flake8-pyi | ||
| "Q", # flake8-quotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha!
| return (self.iter_expr, self.body) | ||
|
|
||
| def _edgeql(self, ctx: ScopeContext) -> str: | ||
| ctx.bind(self.var) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't this get bound in for_?
| iter_expr = _qb.edgeql_qb_expr(iterator) | ||
| scope = _qb.Scope() | ||
| var = _qb.Variable(type_=iter_expr.type, scope=scope) | ||
| body_ = body(_qb.AnnotatedVar(iterator.__gel_origin__, var)) # type: ignore [arg-type, attr-defined] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iterator.gel_origin might be a pure type[GelModel] if you just passed an object type class, e.g for_(User, ...), so you need to check iterator is really a BaseAlias
70098bc to
10b7da6
Compare
Following Elvis's original branch, I added it to a
gel.qbmodule.I also, on Elvis's suggestion, modified
stdto re-export everythingfrom
gel.qb.I renamed his
foreachtofor_to better match EdgeQL.Fixes #729.