Skip to content

Commit

Permalink
add * and ** to docs. expose register_op and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoud committed Jan 18, 2023
1 parent de604f5 commit 13432c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/custom_spec_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ Now, let's take a look at the interesting parts, referencing the comments above:
:ref:`new types and operations to be registered
<setup-and-registration>` with the ``TargetRegistry``. Specifier types
should respect this by contextually fetching these standard
operators as demonstrated above. At the time of writing, three
primary operators are used by glom itself, ``"get"``,
``"iterate"``, and ``"assign"``.
operators as demonstrated above. At the time of writing, the
primary operators used by glom itself are ``"get"``,
``"iterate"``, ``"keys"``, ``"assign"``, and ``"delete"``.
5. In the event that the current target does not support your
Specifier type's desired operation, it's customary to raise a helpful
error. Consider creating your own exception type and inheriting
Expand Down
1 change: 1 addition & 0 deletions glom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Fill,
Auto,
register,
register_op,
Glommer,
Call,
Invoke,
Expand Down
23 changes: 20 additions & 3 deletions glom/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ class Path(object):
Path('a')
>>> path[-2:]
Path(1, 2)
To build a Path object from a string, use :meth:`Path.from_text()`.
This is the default behavior when the top-level :func:`~glom.glom`
function gets a string spec.
"""
def __init__(self, *path_parts):
if not path_parts:
Expand Down Expand Up @@ -655,6 +659,7 @@ def from_text(cls, text):
>>> Path.from_text('a.b.c')
Path('a', 'b', 'c')
This is the default behavior when :func:`~glom.glom` gets a string spec.
"""
def create():
segs = text.split('.')
Expand Down Expand Up @@ -2209,9 +2214,21 @@ def glom(target, spec, **kwargs):
'c'
Here the *spec* was just a string denoting a path,
``'a.b.``. As simple as it should be. The next example shows
how to use nested data to access many fields at once, and make
a new nested structure.
``'a.b.``. As simple as it should be. You can also use
:mod:`glob`-like wildcard selectors:
>>> target = {'a': [{'k': 'v1'}, {'k': 'v2'}]}
>>> glom(target, 'a.*.k')
['v1', 'v2']
In addition to ``*``, you can also use ``**`` for recursive access:
>>> target = {'a': [{'k': 'v3'}, {'k': 'v4'}], 'k': 'v0'}
>>> glom(target, '**.k')
['v0', 'v3', 'v4']
The next example shows how to use nested data to
access many fields at once, and make a new nested structure.
Constructing, or restructuring more-complicated nested data:
Expand Down

0 comments on commit 13432c2

Please sign in to comment.