From 028305289ef2b24fd7bb752dabc13d2471fcff70 Mon Sep 17 00:00:00 2001 From: Bruno Bord Date: Fri, 24 Apr 2020 11:44:29 +0200 Subject: [PATCH] The ``IsoRegistry.items()`` method has been removed from the API This is a **BREAKING CHANGE**. You must use the ``get_calendars()`` to perform the same registry queries refs #375, closes #491. --- Changelog.md | 2 +- docs/iso-registry.md | 4 ++-- workalendar/registry.py | 19 ------------------- workalendar/tests/test_registry.py | 16 +--------------- 4 files changed, 4 insertions(+), 37 deletions(-) diff --git a/Changelog.md b/Changelog.md index 828a798..6f8a89e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,7 +2,7 @@ ## master (unreleased) -Nothing here yet. +* **BREAKING CHANGE**: the ``IsoRegistry.items()`` method has been removed from the API. You must use the ``get_calendars()`` to perform the same registry queries (#375, #491). ## v8.4.0 (2020-04-17) diff --git a/docs/iso-registry.md b/docs/iso-registry.md index e1d6a4f..6f98461 100644 --- a/docs/iso-registry.md +++ b/docs/iso-registry.md @@ -8,7 +8,7 @@ As of version 3.0 (August/September 2018), we have introduced a global calendar ```python >>> from workalendar.registry import registry ->>> calendars = registry.get_calendars() +>>> calendars = registry.get_calendars() # This returns a dictionary >>> for code, calendar_class in calendars.items(): ... print("`{}` is code for '{}'".format(code, calendar_class.name)) `AT` is code for 'Austria' @@ -26,7 +26,7 @@ As of version 3.0 (August/September 2018), we have introduced a global calendar The "private property" `registry.region_registry` is a `dict` object, with the ISO code as a key, and the calendar class as the value. As a "workalendar standard", **every** calendar in the registry has a `name` property (derived from the docstring), so you'd probably be able to build a user-friendly list of available calendars, for a dropdown list, for example. -**DEPRECATION WARNING**: the ``get_calendars`` method used to be named ``items()``. In a future release, it'll be deprecated and re-purposed. Please switch to using ``get_calendars()`` for all your queries in the registry. +**DEPRECATION WARNING**: As of version 9.0.0, the ``IsoRegistry.items()`` has been renamed into ``IsoRegistry.get_calendars()`` for all your queries in the registry. ## Retrieve a collection of regions diff --git a/workalendar/registry.py b/workalendar/registry.py index 4590b3b..e14c0ae 100644 --- a/workalendar/registry.py +++ b/workalendar/registry.py @@ -1,5 +1,4 @@ from importlib import import_module -import warnings from .core import Calendar from .exceptions import ISORegistryError @@ -91,24 +90,6 @@ class IsoRegistry: items[key] = value return items - def items(self, region_codes=None, include_subregions=False): - """ - Returns calendar classes for regions - - :param region_codes list of ISO codes for selected regions. If empty, - the function will return all items from the - registry. - :param include_subregions boolean if subregions - of selected regions should be included in result - :rtype dict - :return dict where keys are ISO codes strings - and values are calendar classes - """ - warnings.warn("The ``items()`` method will soon be deprecated." - " Please use ``get_calendars()`` instead.", - DeprecationWarning) - return self.get_calendars(region_codes, include_subregions) - def get_calendars(self, region_codes=None, include_subregions=False): """ Returns calendar classes for regions diff --git a/workalendar/tests/test_registry.py b/workalendar/tests/test_registry.py index ad4e8ab..458d5f3 100644 --- a/workalendar/tests/test_registry.py +++ b/workalendar/tests/test_registry.py @@ -1,5 +1,4 @@ from unittest import TestCase -import warnings from ..core import Calendar from ..exceptions import ISORegistryError @@ -48,19 +47,6 @@ class NonStandardRegistryTest(TestCase): # Unknown code/region self.assertIsNone(registry.get_calendar_class('XX')) - def test_items_deprecation(self): - registry = IsoRegistry(load_standard_modules=False) - with warnings.catch_warnings(record=True) as w: - # Cause all warnings to always be triggered. - warnings.simplefilter("always") - # Trigger a warning. - registry.items() - # Verify some things - self.assertEqual(len(w), 1) - warning = w[0] - self.assertTrue(issubclass(warning.category, DeprecationWarning)) - self.assertIn("deprecated", str(warning.message)) - def test_get_subregions(self): registry = IsoRegistry(load_standard_modules=False) registry.register('RE', self.region) @@ -144,7 +130,7 @@ class NonStandardRegistryTest(TestCase): self.assertEqual(set({"RE", "RE2", "RE3"}), set(calendars.keys())) # Should be equivalent to [] + include subregions - calendars = registry.items(include_subregions=True) + calendars = registry.get_calendars(include_subregions=True) self.assertEqual(len(calendars), 4) self.assertEqual( set({"RE", "RE2", "RE3", "RE-SR"}),