Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 32fc2e3

Browse filesBrowse files
committed
docs(query_list): Doc improvements
1 parent 6b7af86 commit 32fc2e3
Copy full SHA for 32fc2e3

File tree

Expand file treeCollapse file tree

1 file changed

+33
-31
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+33
-31
lines changed

‎src/libvcs/_internal/query_list.py

Copy file name to clipboardExpand all lines: src/libvcs/_internal/query_list.py
+33-31Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def keygetter(
2121
2222
**With dictionaries**:
2323
24-
>>> keygetter({ "menu": { "breakfast": "cereal" } }, "menu")
24+
>>> keygetter({ "food": { "breakfast": "cereal" } }, "food")
2525
{'breakfast': 'cereal'}
2626
27-
>>> keygetter({ "menu": { "breakfast": "cereal" } }, "menu__breakfast")
27+
>>> keygetter({ "food": { "breakfast": "cereal" } }, "food__breakfast")
2828
'cereal'
2929
3030
**With objects**:
@@ -33,7 +33,7 @@ def keygetter(
3333
>>> from dataclasses import dataclass, field
3434
3535
>>> @dataclass()
36-
... class Menu:
36+
... class Food:
3737
... fruit: list[str] = field(default_factory=list)
3838
... breakfast: Optional[str] = None
3939
@@ -43,14 +43,14 @@ def keygetter(
4343
... place: str
4444
... city: str
4545
... state: str
46-
... menu: Menu = field(default_factory=Menu)
46+
... food: Food = field(default_factory=Food)
4747
4848
4949
>>> restaurant = Restaurant(
5050
... place="Largo",
5151
... city="Tampa",
5252
... state="Florida",
53-
... menu=Menu(
53+
... food=Food(
5454
... fruit=["banana", "orange"], breakfast="cereal"
5555
... )
5656
... )
@@ -59,12 +59,12 @@ def keygetter(
5959
Restaurant(place='Largo',
6060
city='Tampa',
6161
state='Florida',
62-
menu=Menu(fruit=['banana', 'orange'], breakfast='cereal'))
62+
food=Food(fruit=['banana', 'orange'], breakfast='cereal'))
6363
64-
>>> keygetter(restaurant, "menu")
65-
Menu(fruit=['banana', 'orange'], breakfast='cereal')
64+
>>> keygetter(restaurant, "food")
65+
Food(fruit=['banana', 'orange'], breakfast='cereal')
6666
67-
>>> keygetter(restaurant, "menu__breakfast")
67+
>>> keygetter(restaurant, "food__breakfast")
6868
'cereal'
6969
"""
7070
try:
@@ -365,7 +365,7 @@ class QueryList(list[T]):
365365
>>> from dataclasses import dataclass, field
366366
367367
>>> @dataclass()
368-
... class Menu:
368+
... class Food:
369369
... fruit: list[str] = field(default_factory=list)
370370
... breakfast: Optional[str] = None
371371
@@ -375,33 +375,35 @@ class QueryList(list[T]):
375375
... place: str
376376
... city: str
377377
... state: str
378-
... menu: Menu = field(default_factory=Menu)
379-
380-
381-
>>> restaurant = Restaurant(
382-
... place="Largo",
383-
... city="Tampa",
384-
... state="Florida",
385-
... menu=Menu(
386-
... fruit=["banana", "orange"], breakfast="cereal"
378+
... food: Food = field(default_factory=Food)
379+
380+
381+
>>> query = QueryList([
382+
... Restaurant(
383+
... place="Largo",
384+
... city="Tampa",
385+
... state="Florida",
386+
... food=Food(
387+
... fruit=["banana", "orange"], breakfast="cereal"
388+
... )
389+
... ),
390+
... Restaurant(
391+
... place="Chicago suburbs",
392+
... city="Elmhurt",
393+
... state="Illinois",
394+
... food=Food(
395+
... fruit=["apple", "cantelope"], breakfast="waffles"
396+
... )
387397
... )
388-
... )
389-
390-
>>> restaurant
391-
Restaurant(place='Largo',
392-
city='Tampa',
393-
state='Florida',
394-
menu=Menu(fruit=['banana', 'orange'], breakfast='cereal'))
395-
396-
>>> query = QueryList([restaurant])
398+
... ])
397399
398-
>>> query.filter(menu__fruit__in="banana")
400+
>>> query.filter(food__fruit__in="banana")
399401
[Restaurant(place='Largo',
400402
city='Tampa',
401403
state='Florida',
402-
menu=Menu(fruit=['banana', 'orange'], breakfast='cereal'))]
404+
food=Food(fruit=['banana', 'orange'], breakfast='cereal'))]
403405
404-
>>> query.filter(menu__fruit__in="banana")[0].city
406+
>>> query.filter(food__fruit__in="banana")[0].city
405407
'Tampa'
406408
"""
407409

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.