task: metadata: install: pip install -e .
patch: diff --git a/yamlpath/processor.py b/yamlpath/processor.py
index 1d3edc3..5a124fa 100644
--- a/yamlpath/processor.py
+++ b/yamlpath/processor.py
@@ -991,17 +991,15 @@ class Processor:
 
         elif isinstance(data, (set, CommentedSet)):
             for ele in data:
-                if ele == stripped_attrs or (
-                    isinstance(ele, TaggedScalar)
-                    and ele.value == stripped_attrs
-                ):
+                ele_val = ele.value if isinstance(ele, TaggedScalar) else ele
+                if ele_val == stripped_attrs:
                     self.logger.debug((
                         "Processor::_get_nodes_by_key:  FOUND set node by"
                         " name at {}."
                         ).format(str_stripped))
                     next_translated_path = (translated_path +
                         YAMLPath.escape_path_section(
-                            ele, translated_path.seperator))
+                            ele_val, translated_path.seperator))
                     next_ancestry = ancestry + [(data, ele)]
                     yield NodeCoords(
                         ele, data, stripped_attrs,
@@ -2528,7 +2526,7 @@ class Processor:
     # pylint: disable=too-many-arguments
     def _update_node(
         self, parent: Any, parentref: Any, value: Any,
-        value_format: YAMLValueFormats, value_tag: str = None
+        value_format: YAMLValueFormats, value_tag: Union[str, None] = None
     ) -> None:
         """
         Set the value of a data node.
@@ -2560,13 +2558,13 @@ class Processor:
         # author of ruamel.yaml, to resolve how to update all references to an
         # Anchor throughout the parsed data structure.
         def recurse(data, parent, parentref, reference_node, replacement_node):
-            if isinstance(data, (CommentedMap, dict)):
+            if isinstance(data, CommentedMap):
                 for i, k in [
                         (idx, key) for idx, key in enumerate(data.keys())
                         if key is reference_node
                 ]:
                     data.insert(i, replacement_node, data.pop(k))
-                for k, val in data.items():
+                for k, val in data.non_merged_items():
                     if val is reference_node:
                         if (hasattr(val, "anchor") or
                                 (data is parent and k == parentref)):
@@ -2585,6 +2583,7 @@ class Processor:
                 data.discard(reference_node)
                 data.add(replacement_node)
 
+        change_node = None
         if isinstance(parent, (set, CommentedSet)):
             for ele in parent:
                 if ele == parentref:

problem_statement: Bug: Unexpected YAML Merge Key expansion when changing format and value of Anchored child nodes
## Operating System

1. Name/Distribution: Windows
2. Version: 10

## Version of Python and packages in use at the time of the issue.

1. [Distribution](https://wiki.python.org/moin/PythonDistributions): CPython
2. Python Version: 3.x
3. Version of yamlpath installed: 3.6.7
4. Version of ruamel.yaml installed: 0.17.21

## Minimum sample of YAML (or compatible) data necessary to trigger the issue

test_commands_yaml_set.py

```
    def test_update_base_value(self, script_runner, tmp_path_factory):
        yamlin = """---
common: &base
  TEST_COMMON_SETTING: 'a1'
TestService:
  <<: *base
"""
        yamlout = """---
common: &base
  TEST_COMMON_SETTING: a2
TestService:
  <<: *base
  TEST_COMMON_SETTING: a2
"""
        yaml_file = create_temp_yaml_file(tmp_path_factory, yamlin)
        result = script_runner.run(
            self.command,
            "--change=common.TEST_COMMON_SETTING",
            "--value=a2",
            yaml_file
        )
        assert result.success, result.stderr

        with open(yaml_file, 'r') as fhnd:
            filedat = fhnd.read()
        assert filedat == yamlout
```

## Expected Outcome
```
---
common: &base
  TEST_COMMON_SETTING: a2
TestService:
  <<: *base
```

if you change `TEST_COMMON_SETTING: 'a1'` -> `TEST_COMMON_SETTING: a1` then everything is ok.

looks like bug in check:
```
def recurse(data, parent, parentref, reference_node, replacement_node):
...
    if (hasattr(val, "anchor"):
```
value with type `SingelQuotedScalarString` has an attr `anchor`.
repo: wwkimball/yamlpath
test_cmd: pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
test_patch: diff --git a/tests/test_commands_yaml_set.py b/tests/test_commands_yaml_set.py
index 74069d3..5b1dbc4 100644
--- a/tests/test_commands_yaml_set.py
+++ b/tests/test_commands_yaml_set.py
@@ -346,24 +346,6 @@ boolean: false
         assert not result.success, result.stderr
         assert "Cannot add" in result.stderr
 
-    @requireseyaml
-    def test_bad_decryption(self, script_runner, tmp_path_factory, old_eyaml_keys):
-        content = """---
-        encrypted: ENC[PKCS7,MIIx...broken-on-purpose...==]
-        """
-        yaml_file = create_temp_yaml_file(tmp_path_factory, content)
-        result = script_runner.run(
-            self.command,
-            "--change=encrypted",
-            "--random=1",
-            "--check=n/a",
-            "--privatekey={}".format(old_eyaml_keys[0]),
-            "--publickey={}".format(old_eyaml_keys[1]),
-            yaml_file
-        )
-        assert not result.success, result.stderr
-        assert "Unable to decrypt value!" in result.stderr
-
     @requireseyaml
     def test_good_encryption(self, script_runner, tmp_path_factory, old_eyaml_keys):
         import re
@@ -1542,3 +1524,35 @@ hash:
         )
         assert not result.success, result.stderr
         assert "Cannot add YAML Merge Keys to non-Hash" in result.stderr
+
+    def test_ymk_anchor_child_format_change(self, script_runner, tmp_path_factory):
+        """
+        Test that changing the FORMAT and value of an anchored Hash node does
+        not cause unexpected expansion at the YAML Merge Key anchor of the
+        Hash.
+        """
+        # Thanks to https://github.com/hemnstill!
+        yamlin = """---
+common: &base
+  TEST_COMMON_SETTING: 'a1'
+TestService:
+  <<: *base
+"""
+        yamlout = """---
+common: &base
+  TEST_COMMON_SETTING: a2
+TestService:
+  <<: *base
+"""
+        yaml_file = create_temp_yaml_file(tmp_path_factory, yamlin)
+        result = script_runner.run(
+            self.command,
+            "--change=common.TEST_COMMON_SETTING",
+            "--value=a2",
+            yaml_file
+        )
+        assert result.success, result.stderr
+
+        with open(yaml_file, 'r') as fhnd:
+            filedat = fhnd.read()
+        assert filedat == yamlout