Skip to content

Commit

Permalink
Rename to @frozen_after_init
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano committed Oct 9, 2019
1 parent c0fee7a commit 71f55b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/python/pants/util/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def staticproperty(func: Union[staticmethod, Callable]) -> ClassPropertyDescript
return ClassPropertyDescriptor(func, doc)


def freeze_after_init(cls: Type[T]) -> Type[T]:
def frozen_after_init(cls: Type[T]) -> Type[T]:
"""Class decorator to freeze any modifications to the object after __init__() is done.
The primary use case is for @dataclasses who cannot use frozen=True due to the need for a custom
Expand Down
14 changes: 7 additions & 7 deletions tests/python/pants_test/util/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from abc import ABC, abstractmethod
from dataclasses import FrozenInstanceError, dataclass

from pants.util.meta import SingletonMetaclass, classproperty, freeze_after_init, staticproperty
from pants.util.meta import SingletonMetaclass, classproperty, frozen_after_init, staticproperty
from pants_test.test_base import TestBase


Expand Down Expand Up @@ -249,7 +249,7 @@ def f(cls):
class FreezeAfterInitTest(unittest.TestCase):

def test_no_init(self) -> None:
@freeze_after_init
@frozen_after_init
class Test:
pass

Expand All @@ -258,7 +258,7 @@ class Test:
test.x = 1

def test_init_still_works(self):
@freeze_after_init
@frozen_after_init
class Test:

def __init__(self, x: int) -> None:
Expand All @@ -270,7 +270,7 @@ def __init__(self, x: int) -> None:
self.assertEqual(test.y, "abc")

def test_modify_preexisting_field_after_init(self) -> None:
@freeze_after_init
@frozen_after_init
class Test:

def __init__(self, x: int) -> None:
Expand All @@ -281,7 +281,7 @@ def __init__(self, x: int) -> None:
test.x = 1

def test_add_new_field_after_init(self) -> None:
@freeze_after_init
@frozen_after_init
class Test:

def __init__(self, x: int) -> None:
Expand All @@ -292,7 +292,7 @@ def __init__(self, x: int) -> None:
test.y = "abc"

def test_explicitly_call_setattr_after_init(self) -> None:
@freeze_after_init
@frozen_after_init
class Test:

def __init__(self, x: int) -> None:
Expand All @@ -303,7 +303,7 @@ def __init__(self, x: int) -> None:
setattr(test, "x", 1)

def test_works_with_dataclass(self) -> None:
@freeze_after_init
@frozen_after_init
@dataclass(frozen=False)
class Test:
x: int
Expand Down

0 comments on commit 71f55b6

Please sign in to comment.