diff --git a/neutron_lib/constants.py b/neutron_lib/constants.py index a49e67a..3af197b 100644 --- a/neutron_lib/constants.py +++ b/neutron_lib/constants.py @@ -258,6 +258,10 @@ class Sentinel(object): # Always return the same object because this is essentially a constant. return self + def __copy__(self): + # called via copy.copy(x) + return self + ############################# # Attribute related constants diff --git a/neutron_lib/tests/unit/test_neutron_lib.py b/neutron_lib/tests/unit/test_neutron_lib.py index b3aeac9..db5089b 100644 --- a/neutron_lib/tests/unit/test_neutron_lib.py +++ b/neutron_lib/tests/unit/test_neutron_lib.py @@ -25,3 +25,7 @@ class TestNeutronLib(base.BaseTestCase): foo = constants.Sentinel() bar = copy.deepcopy(foo) self.assertEqual(id(foo), id(bar)) + + def test_sentinel_copy(self): + singleton = constants.Sentinel() + self.assertEqual(copy.deepcopy(singleton), copy.copy(singleton))