I expect this probably has something to do with the interaction of multi and array attributes, and probably generalizes. But I've only actually tested it as encountered on constraints.
This was tested in Maya 2022.2, but I don't think it's a recent development.
IIRC I've encountered it a few years ago.
# create two cubes
a, _ = pm.polyCube(name='a')
b, _ = pm.polyCube(name='b')
# offset the first one
a.t.set(1, 2, 3)
a.r.set(30, 60, 90)
# constrain the other, with offset
c = pm.parentConstraint(a, b, mo=True, name='c')
# now attempt to navigate the Attribute hierarchy of the constraint node
# the objective will be to get an Attribute object representing c.target[0].targetOffsetRotateX
# we can get there fine by giving PyNode the full path
attrPath = c.name() + '.' + testAttr.longName()
print(attrPath) # c.target[0].targetOffsetRotateX
attr = pm.PyNode(attrPath) # Result: Attribute('c.target[0].targetOffsetRotateX') #
print(attr) # c.target[0].targetOffsetRotateX
# we can also get there by querying the child list of the targetOffsetRotate attribute
assert c.target[0].targetOffsetRotate.children()[0] == pm.PyNode('c.target[0].targetOffsetRotateX') # Succeeds.
# but if we attempt to navigate using the long name of the child attribute, pymel returns the wrong result.
assert c.target[0].targetOffsetRotateX == pm.PyNode('c.target[0].targetOffsetRotateX') # AssertionError!
print(c.target[0].targetOffsetRotateX)
# c.target[0]
assert c.target[0].targetOffsetRotateX != c.target[0] # AssertionError!
Below is an example that fails.
I expect this probably has something to do with the interaction of multi and array attributes, and probably generalizes. But I've only actually tested it as encountered on constraints.
This was tested in Maya 2022.2, but I don't think it's a recent development. IIRC I've encountered it a few years ago.