Nodes/comfy-ovum/_.isDictlike
ComfyUI Node

_.isDictlike

The duck-typed 'does this behave like a dict?' check

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.isDictlike
  • obj
  • *

_.isDictlike answers the duck-typed version of a question you'll actually hit: does this value behave like a dictionary? Where _.isDict demands type(x) is dict exactly, this node tests whether an object acts like a dict - has the methods you'd call on one. It's the difference between "is it literally a dict" and "can I treat it as one," and for real-world ComfyUI data, the second question is often the useful one.

How it works

The port checks for the presence of the dict protocol's method set:

def isDictlike(self):
    return self._wrap(_.all(_.getmanyattr(self.obj, 'items', 'values', 'keys', 'get', None),
                            lambda x, *a: callable(x)))

It grabs the attributes items, values, keys, and get from the object (defaulting to None when missing) and confirms every one of them is callable. If all four exist and are callable, the value "is dictlike." A plain dict passes. A custom mapping class that implements the protocol passes. A JSON string or a list fails, because it has none of those methods.

The inputs that matter

One input, one output:

  • obj - the primary input (*), the value being inspected. Also accepts a _.CHAIN to continue chaining.

Output is a single * - a real bool at runtime, untyped on the socket, since the auto-generator only types the standard Underscore.js method names and isDictlike is a Python-port extra.

Where you'd actually use it

Whenever you don't care about the exact type, only whether you can index and iterate it like a map. The defensive pattern from _.isDict applies here but looser: a value from a settings reader or a data source might be a plain dict, an OrderedDict, or some custom mapping, and _.isDictlike says "good enough, feed it to the dict consumer." Pair it with _.isDict when you need both answers - exact vs. duck-typed - before routing data.

Installing

Part of comfy-ovum (MIT). ComfyUI Manager → search comfy-ovum → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

No extra dependencies for the underscore nodes - the bundled underscore3 port handles them.

Gotchas

The check is shallow - it verifies the methods exist and are callable, not that they behave correctly, so a broken mapping object can still pass. Output is untyped *, and the pack README's WIP warning covers the whole family. For a quick "can I treat this as a dict?" gate, it's exactly right; just don't expect it to certify the mapping's behavior.

Categoryovum/underscore

Inputs (1)

NameTypeDefaultDescription
objopt*Primary input object. Also accepts _.CHAIN to continue chaining.

Outputs (1)

NameTypeDescription
**