Skip to content

Commit

Permalink
Rename setters.DISABLE to setters.NO_OP to clarify its purpose
Browse files Browse the repository at this point in the history
DISABLE sounds less purposeful and doesn't convey its meaning as well.
  • Loading branch information
hynek committed Jul 20, 2020
1 parent 3fcb126 commit 15d58c1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ These are helpers that you can use together with `attr.s`'s and `attr.ib`'s ``on
.. autofunction:: attr.setters.validate
.. autofunction:: attr.setters.convert
.. autofunction:: attr.setters.pipe
.. autodata:: attr.setters.DISABLE
.. autodata:: attr.setters.NO_OP

For example, only ``x`` is frozen here:

Expand All @@ -540,7 +540,7 @@ These are helpers that you can use together with `attr.s`'s and `attr.ib`'s ``on
>>> @attr.s(on_setattr=attr.setters.frozen)
... class C(object):
... x = attr.ib()
... y = attr.ib(on_setattr=attr.setters.DISABLE)
... y = attr.ib(on_setattr=attr.setters.NO_OP)
>>> c = C(1, 2)
>>> c.y = 3
>>> c.y
Expand Down
12 changes: 6 additions & 6 deletions src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ def attrib(
parameter is ignored).
:param on_setattr: Allows to overwrite the *on_setattr* setting from
`attr.s`. If left `None`, the *on_setattr* value from `attr.s` is used.
Set to `attr.setters.DISABLE` to run **no** `setattr` hooks for this
Set to `attr.setters.NO_OP` to run **no** `setattr` hooks for this
attribute -- regardless of the setting in `attr.s`.
:type on_setattr: `callable`, or a list of callables, or `None`, or
`attr.setters.DISABLE`
`attr.setters.NO_OP`
.. versionadded:: 15.2.0 *convert*
.. versionadded:: 16.3.0 *metadata*
Expand Down Expand Up @@ -797,7 +797,7 @@ def add_init(self):
self._base_attr_map,
self._is_exc,
self._on_setattr is not None
and self._on_setattr is not setters.DISABLE,
and self._on_setattr is not setters.NO_OP,
)
)

Expand Down Expand Up @@ -830,7 +830,7 @@ def add_setattr(self):
sa_attrs = {}
for a in self._attrs:
on_setattr = a.on_setattr or self._on_setattr
if on_setattr and on_setattr is not setters.DISABLE:
if on_setattr and on_setattr is not setters.NO_OP:
sa_attrs[a.name] = a, on_setattr

if not sa_attrs:
Expand Down Expand Up @@ -1765,7 +1765,7 @@ def _make_init(

needs_cached_setattr = True
elif (
has_global_on_setattr and a.on_setattr is not setters.DISABLE
has_global_on_setattr and a.on_setattr is not setters.NO_OP
) or _is_slot_attr(a.name, base_attr_map):
needs_cached_setattr = True

Expand Down Expand Up @@ -1932,7 +1932,7 @@ def fmt_setter_with_converter(

attr_name = a.name
has_on_setattr = a.on_setattr is not None or (
a.on_setattr is not setters.DISABLE and has_global_on_setattr
a.on_setattr is not setters.NO_OP and has_global_on_setattr
)
arg_name = a.name.lstrip("_")

Expand Down
2 changes: 1 addition & 1 deletion src/attr/setters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def convert(instance, attrib, new_value):
return new_value


DISABLE = object()
NO_OP = object()
"""
Sentinel for disabling class-wide *on_setattr* hooks for certain attributes.
Expand Down
4 changes: 2 additions & 2 deletions src/attr/setters.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ def pipe(*setters: _OnSetAttrType) -> _OnSetAttrType: ...
def validate(instance: Any, attribute: Attribute, new_value: _T) -> _T: ...
def convert(instance: Any, attribute: Attribute, new_value: _T) -> _T: ...

_DisableType = NewType("_DisableType", object)
DISABLE: _DisableType
_NoOpType = NewType("_NoOpType", object)
NO_OP: _NoOpType
2 changes: 1 addition & 1 deletion tests/typing_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class OrderFlags:
@attr.s(on_setattr=attr.setters.validate)
class ValidatedSetter:
a = attr.ib()
b = attr.ib(on_setattr=attr.setters.DISABLE)
b = attr.ib(on_setattr=attr.setters.NO_OP)
c = attr.ib(on_setattr=attr.setters.frozen)
d = attr.ib(on_setattr=[attr.setters.convert, attr.setters.validate])
d = attr.ib(
Expand Down

0 comments on commit 15d58c1

Please sign in to comment.