Skip to content

Commit 25cc742

Browse files
committed
Use mutating_method decorator for FrozenPhoneNumber
1 parent f18f9db commit 25cc742

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

python/phonenumbers/phonenumber.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
19-
from .util import UnicodeMixin, ImmutableMixin
19+
from .util import UnicodeMixin, ImmutableMixin, mutating_method
2020

2121

2222
class CountryCodeSource(object):
@@ -215,13 +215,10 @@ def __hash__(self):
215215
self.country_code_source,
216216
self.preferred_domestic_carrier_code))
217217

218+
@mutating_method
218219
def __init__(self, *args, **kwargs):
219-
old_mutable = self._mutable
220-
self._mutable = True
221-
try:
222-
if len(kwargs) == 0 and len(args) == 1 and isinstance(args[0], PhoneNumber):
223-
super(FrozenPhoneNumber, self).__init__(**args[0].__dict__)
224-
else:
225-
super(FrozenPhoneNumber, self).__init__(*args, **kwargs)
226-
finally:
227-
self._mutable = old_mutable
220+
if len(kwargs) == 0 and len(args) == 1 and isinstance(args[0], PhoneNumber):
221+
# Copy constructor
222+
super(FrozenPhoneNumber, self).__init__(**args[0].__dict__)
223+
else:
224+
super(FrozenPhoneNumber, self).__init__(*args, **kwargs)

0 commit comments

Comments
 (0)