@@ -148,18 +148,18 @@ to see the other functionalities.
148148 rules = default_registry.get_overrides()
149149
150150 # Or, we could also filter out the rules by the module they were defined in
151- rules = default_registry.get_overrides_from( " my_project.page_objects" )
151+ rules = default_registry.get_overrides( filters = " my_project.page_objects" )
152152
153153 print (len (rules)) # 3
154154 print (rules[0 ]) # OverrideRule(for_patterns=Patterns(include=['example.com'], exclude=[], priority=500), use=<class 'my_project.page_objects.ExampleProductPage'>, instead_of=<class 'my_project.page_objects.GenericProductPage'>, meta={})
155155
156156 .. note ::
157157
158158 Notice in the code sample above where we could filter out the Override rules
159- per module via :meth: ` ~.PageObjectRegistry.get_overrides_from ` . This
160- could also offer another alternative way to organize your Page Object rules
161- using only the `` default_registry ``. There's no need to declare multiple
162- :class: ` ~.PageObjectRegistry ` instances and use multiple annotations.
159+ per module via the `` filters `` param . This could also offer another alternative
160+ way to organize your Page Object rules using only the `` default_registry ``.
161+ There's no need to declare multiple :class: ` ~.PageObjectRegistry ` instances
162+ and use multiple annotations.
163163
164164.. warning ::
165165
@@ -182,8 +182,12 @@ to see the other functionalities.
182182 consume_modules(" external_package_A.po" , " another_ext_package.lib" )
183183 rules = default_registry.get_overrides()
184184
185- **NOTE **: :func: `~.web_poet.overrides.consume_modules ` must be called before
186- :meth: `~.PageObjectRegistry.get_overrides ` for the imports to properly load.
185+ # Fortunately, `get_overrides()` provides a shortcut for the lines above:
186+ rules = default_registry.get_overrides(consume = [" external_package_A.po" , " another_ext_package.lib" ])
187+
188+ **NOTE **: :func: `~.web_poet.overrides.consume_modules ` or the ``consume `` param
189+ of :meth: `~.PageObjectRegistry.get_overrides ` for the imports to properly load.
190+ Most especially if you intend to use Page Objects from externally imported packages.
187191
188192
189193A handy CLI tool is also available at your disposal to quickly see the available
@@ -254,16 +258,16 @@ Then we could easily retrieve all Page Objects per subpackage or module like thi
254258 from web_poet import default_registry, consume_modules
255259
256260 # We can do it per website.
257- rules_gadget = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site" )
258- rules_furniture = default_registry.get_overrides_from( " my_page_obj_project.furniture_site" )
261+ rules_gadget = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site" )
262+ rules_furniture = default_registry.get_overrides( filters = " my_page_obj_project.furniture_site" )
259263
260264 # It can also drill down to the country domains on a given site.
261- rules_gadget_us = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site.us" )
262- rules_gadget_fr = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site.fr" )
265+ rules_gadget_us = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site.us" )
266+ rules_gadget_fr = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site.fr" )
263267
264268 # Or even drill down further to the specific module.
265- rules_gadget_us_products = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site.us.products" )
266- rules_gadget_us_listings = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site.us.product_listings" )
269+ rules_gadget_us_products = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site.us.products" )
270+ rules_gadget_us_listings = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site.us.product_listings" )
267271
268272 # Or simply all of the Override rules ever declared.
269273 rules = default_registry.get_overrides()
@@ -273,11 +277,16 @@ Then we could easily retrieve all Page Objects per subpackage or module like thi
273277 consume_modules(" external_package_A.po" , " another_ext_package.lib" )
274278 rules = default_registry.get_overrides()
275279
280+ # Remember, a shortcut for consuming imports would be:
281+ rules = default_registry.get_overrides(consume = [" external_package_A.po" , " another_ext_package.lib" ])
282+
283+
276284 .. warning ::
277285
278286 Remember to consider calling :func: `~.web_poet.overrides.consume_modules `
279- when using :meth: `~.PageObjectRegistry.get_overrides ` in case you have some
280- external package containing Page Objects of interest.
287+ or the ``consume `` param of :meth: `~.PageObjectRegistry.get_overrides ` for the
288+ imports to properly load. Most especially if you intend to use Page Objects
289+ from externally imported packages.
281290
282291 This enables the :meth: `~.PageObjectRegistry.handle_urls ` that annotates
283292 the external Page Objects to be properly loadeded.
@@ -301,9 +310,9 @@ hierarchy** like this:
301310 ├── furniture_shop_products.py
302311 └── furniture_shop_product_listings.py
303312
304- As such, calling ``default_registry.get_overrides_from () `` would not work
305- on projects with a **flat hierarchy **. Thus, we can organize them using our own
306- instances of the :class: `~.PageObjectRegistry ` instead:
313+ As such, calling ``default_registry.get_overrides () `` with a `` from `` parameter
314+ would not effectively work on projects with a **flat hierarchy **. Thus, we can
315+ organize them using our own instances of the :class: `~.PageObjectRegistry ` instead:
307316
308317.. code-block :: python
309318
@@ -385,10 +394,12 @@ retrieve such rules would be:
385394
386395 from web_poet import default_registry
387396
388- product_listing_rules = default_registry.get_overrrides_from(
389- " my_page_obj_project.cool_gadget_site.us.product_listings" ,
390- " my_page_obj_project.cool_gadget_site.fr.product_listings" ,
391- " my_page_obj_project.furniture_shop.product_listings"
397+ product_listing_rules = default_registry.get_overrrides(
398+ filters = [
399+ " my_page_obj_project.cool_gadget_site.us.product_listings" ,
400+ " my_page_obj_project.cool_gadget_site.fr.product_listings" ,
401+ " my_page_obj_project.furniture_shop.product_listings" ,
402+ ]
392403 )
393404
394405 On the other hand, we can also create another :class: `~.PageObjectRegistry ` instance
@@ -431,7 +442,7 @@ Retrieving all of the Product Listing Override rules would simply be:
431442 rules = product_listings_registry.get_overrides()
432443
433444 # We can also filter it down further on a per site basis if needed.
434- rules = product_listings_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site" )
445+ rules = product_listings_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site" )
435446
436447 Using Overrides from External Packages
437448--------------------------------------
@@ -461,6 +472,9 @@ packages** in your project, you can do it like:
461472 import gadget_sites_page_objects
462473 from web_poet import PageObjectRegistry, consume_modules, default_registry
463474
475+ # We're using `consume_modules()` here instead of the `consume` param of
476+ # `PageObjectRegistry.get_overrides()` since we need to access the `data`
477+ # attribute of the registry even before calling `PageObjectRegistry.get_overrides()`
464478 consume_modules(" ecommerce_page_objects" , " gadget_sites_page_objects" )
465479
466480 combined_registry = PageObjectRegistry()
0 commit comments