kwmonroe: There was some chatter on #juju about not using a string representation for toggle (instead using `object()`).  I'm fine with this as-in, or with that changed.
stub42: This needs a test, which I suspect is trivial.
diff --git a/charms/reactive/relations.py b/charms/reactive/relations.py
index 173ef28..a8c1499 100644
--- a/charms/reactive/relations.py
+++ b/charms/reactive/relations.py
@@ -30,7 +30,9 @@ from charms.reactive.bus import _load_module
 from charms.reactive.bus import StateList
 
 
-ALL = '__ALL_SERVICES__'
+# arbitrary obj instances to use as defaults instead of None
+ALL = object()
+TOGGLE = object()
 
 
 class scopes(object):
@@ -296,13 +298,13 @@ class RelationBase(with_metaclass(AutoAccessors, object)):
         """
         return self.conversation(scope).is_state(state)
 
-    def toggle_state(self, state, active=None, scope=None):
+    def toggle_state(self, state, active=TOGGLE, scope=None):
         """
         Toggle the state for the :class:`Conversation` with the given scope.
 
         In Python, this is equivalent to::
 
-            relation.conversation(scope).toggle_state(state)
+            relation.conversation(scope).toggle_state(state, active)
 
         See :meth:`conversation` and :meth:`Conversation.toggle_state`.
         """
@@ -549,7 +551,7 @@ class Conversation(object):
             return False
         return self.key in value['conversations']
 
-    def toggle_state(self, state, active=None):
+    def toggle_state(self, state, active=TOGGLE):
         """
         Toggle the given state for this conversation.
 
@@ -565,7 +567,7 @@ class Conversation(object):
 
         This will set the state if ``value`` is equal to ``foo``.
         """
-        if active is None:
+        if active is TOGGLE:
             active = not self.is_state(state)
         if active:
             self.set_state(state)

toggle_state default for active is error-prone
`toggle_state` takes an optional `active` param that lets you specify whether the state should be on or off, instead of it being switched from its previous value.  Having a default value of `None` is problematic because `None` can easily be mistaken for a "truthy" `False` when dealing with relation data, which leads to the state being unexpectedly set.  For example, the following breaks:

```python
conv.toggle_state('{relation_name}.feature_x',
                  active=conv.get_remote('feature_x_available'))
```

This can also be more subtle because `None and <anything>` returns `None` instead of `False` as one might expect.  For example, this also breaks:

```python
name = conv.get_remote('name')
version = conv.get_remote('version')
conv.toggle_state('{relation_name}.ready', name and version)
```

diff --git a/tests/test_relations.py b/tests/test_relations.py
index c4977da..d49c3e1 100644
--- a/tests/test_relations.py
+++ b/tests/test_relations.py
@@ -171,6 +171,11 @@ class TestRelationBase(unittest.TestCase):
         rb.conversation.assert_called_once_with('scope')
         conv.toggle_state.assert_called_once_with('state', 'active')
 
+        conv.toggle_state.reset_mock()
+        rb.toggle_state('state')
+        conv.toggle_state.assert_called_once_with('state',
+                                                  relations.TOGGLE)
+
     def test_set_remote(self):
         conv = mock.Mock(name='conv')
         rb = relations.RelationBase('relname', 'unit')
@@ -391,12 +396,14 @@ class TestConversation(unittest.TestCase):
 
         conv.toggle_state('foo')
         self.assertEqual(conv.remove_state.call_count, 1)
+        conv.toggle_state('foo', None)
+        self.assertEqual(conv.remove_state.call_count, 2)
         conv.toggle_state('foo')
         self.assertEqual(conv.set_state.call_count, 1)
         conv.toggle_state('foo', True)
         self.assertEqual(conv.set_state.call_count, 2)
         conv.toggle_state('foo', False)
-        self.assertEqual(conv.remove_state.call_count, 2)
+        self.assertEqual(conv.remove_state.call_count, 3)
 
     @mock.patch.object(relations.hookenv, 'relation_set')
     @mock.patch.object(relations.Conversation, 'relation_ids', ['rel:1', 'rel:2'])

pip install -e .
parse_log_pytest
requirements.txt
coverage mock nose flake8 ipython ipdb pytest
3.6
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
backcall==0.2.0
certifi==2021.5.30
charmhelpers==1.2.1
-e git+https://github.com/juju-solutions/charms.reactive.git@04663e45f3683d4c497f43526d3ac26593ee10a2#egg=charms.reactive
coverage==6.2
decorator==5.1.1
flake8==5.0.4
importlib-metadata==4.2.0
importlib-resources==5.4.0
iniconfig==1.1.1
ipdb==0.13.13
ipython==7.16.3
ipython-genutils==0.2.0
jedi==0.17.2
Jinja2==3.0.3
MarkupSafe==2.0.1
mccabe==0.7.0
mock==5.2.0
netaddr==0.10.1
nose==1.3.7
packaging==21.3
parso==0.7.1
pbr==6.1.1
pexpect==4.9.0
pickleshare==0.7.5
pluggy==1.0.0
prompt-toolkit==3.0.36
ptyprocess==0.7.0
py==1.11.0
pyaml==23.5.8
pycodestyle==2.9.1
pyflakes==2.5.0
Pygments==2.14.0
pyparsing==3.1.4
pytest==7.0.1
PyYAML==6.0.1
six==1.17.0
tomli==1.2.3
traitlets==4.3.3
typing_extensions==4.1.1
wcwidth==0.2.13
zipp==3.6.0

name: charms.reactive
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - backcall==0.2.0
      - charmhelpers==1.2.1
      - coverage==6.2
      - decorator==5.1.1
      - flake8==5.0.4
      - importlib-metadata==4.2.0
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - ipdb==0.13.13
      - ipython==7.16.3
      - ipython-genutils==0.2.0
      - jedi==0.17.2
      - jinja2==3.0.3
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - mock==5.2.0
      - netaddr==0.10.1
      - nose==1.3.7
      - packaging==21.3
      - parso==0.7.1
      - pbr==6.1.1
      - pexpect==4.9.0
      - pickleshare==0.7.5
      - pluggy==1.0.0
      - prompt-toolkit==3.0.36
      - ptyprocess==0.7.0
      - py==1.11.0
      - pyaml==23.5.8
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pyyaml==6.0.1
      - six==1.17.0
      - tomli==1.2.3
      - traitlets==4.3.3
      - typing-extensions==4.1.1
      - wcwidth==0.2.13
      - zipp==3.6.0
prefix: /opt/conda/envs/charms.reactive

tests/test_relations.py::TestRelationBase::test_toggle_state tests/test_relations.py::TestConversation::test_toggle_state
tests/test_relations.py::TestAutoAccessors::test_accessor tests/test_relations.py::TestAutoAccessors::test_accessor_doc tests/test_relations.py::TestRelationBase::test_conversation tests/test_relations.py::TestRelationBase::test_find_impl tests/test_relations.py::TestRelationBase::test_find_subclass tests/test_relations.py::TestRelationBase::test_from_name tests/test_relations.py::TestRelationBase::test_from_state tests/test_relations.py::TestRelationBase::test_get_local tests/test_relations.py::TestRelationBase::test_get_remote tests/test_relations.py::TestRelationBase::test_is_state tests/test_relations.py::TestRelationBase::test_remove_state tests/test_relations.py::TestRelationBase::test_set_local tests/test_relations.py::TestRelationBase::test_set_remote tests/test_relations.py::TestRelationBase::test_set_state tests/test_relations.py::TestConversation::test_depart tests/test_relations.py::TestConversation::test_get_local tests/test_relations.py::TestConversation::test_get_remote tests/test_relations.py::TestConversation::test_is_state tests/test_relations.py::TestConversation::test_join tests/test_relations.py::TestConversation::test_key tests/test_relations.py::TestConversation::test_load tests/test_relations.py::TestConversation::test_relation_ids tests/test_relations.py::TestConversation::test_remove_state tests/test_relations.py::TestConversation::test_set_local tests/test_relations.py::TestConversation::test_set_remote tests/test_relations.py::TestConversation::test_set_state tests/test_relations.py::TestMigrateConvs::test_migrate tests/test_relations.py::TestRelationCall::test_call_conversations tests/test_relations.py::TestRelationCall::test_call_name tests/test_relations.py::TestRelationCall::test_call_state tests/test_relations.py::TestRelationCall::test_no_impl
charms/reactive/relations.py
charms/reactive/relations.py