{"record":{"id":"d1d7a987971e3c08","repo":"jax-ml/jax","slug":"each-element-of-compoundfactor-must-be-a-str-but","errorCode":null,"errorMessage":"Each element of CompoundFactor must be a str, but got {type(factor)}","messagePattern":"Each element of CompoundFactor must be a str, but got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":68,"sourceCode":"    return False\n  return len(factor) == 1 or factor[1:].isdigit()\n\ndef _get_batching_group(factor: str) -> str:\n  \"\"\"Extracts the batching group from a factor for leading batching dimensions.\"\"\"\n  return factor[1:] if len(factor) > 1 else \"0\"\n\nclass CompoundFactor(tuple):\n  \"\"\"Describes the factors for a compound factor.\n\n  A compound factor should contain at least two factors, e.g.\n  * CompoundFactor('b', 'c').\n  \"\"\"\n  def __init__(self, *factors):\n    if len(factors) < 2:\n      raise ValueError(\"A compound factor should contain at least two factors\")\n    for factor in factors:\n      if not isinstance(factor, str):\n        raise ValueError(f\"Each element of CompoundFactor must be a str, but got {type(factor)}\")\n      if _is_batching(factor):\n        raise ValueError(\"Ellipsis can't be used in a compound factor\")\n      else:\n        _check_factor(factor)\n\n  def __new__(cls, *factors):\n    return tuple.__new__(CompoundFactor, factors)\n\n\nclass ArrayMapping(tuple):\n  \"\"\"Describes the factors for an operand or result.\n\n  Each element is either a factor or a CompoundFactor. A leading element can\n  also be BATCHING, which represents batching dimensions. examples:\n  * ArrayMapping('a')\n  * ArrayMapping('b', 'c')\n  * ArrayMapping(CompoundFactor('b', 'c'), 'd')\n  * ArrayMapping(BATCHING, CompoundFactor('b', 'c'), 'd')","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L50-L86","documentation":"Every element of a CompoundFactor must be a plain Python string. Passing any non-str (int, list, another CompoundFactor, etc.) raises ValueError with the offending type.","triggerScenarios":"CompoundFactor(2, 'c'), CompoundFactor(['b'], 'c'), or nested CompoundFactor usage while building sharding rules.","commonSituations":"Building rules programmatically where factor lists may contain ints or nested tuples.","solutions":["Convert elements to strings before constructing: CompoundFactor(str(f1), str(f2))","Flatten nested CompoundFactors into their string components","Add a type check in rule-generation code"],"exampleFix":"# before\nCompoundFactor(mesh_axis_id, 'c')  # int\n\n# after\nCompoundFactor(str(mesh_axis_id), 'c')","handlingStrategy":"type-guard","validationCode":"assert all(isinstance(f, str) for f in factors), [type(f) for f in factors]","typeGuard":"def all_str(factors):\n    return all(isinstance(f, str) for f in factors)","tryCatchPattern":null,"preventionTips":["Coerce factors with str() when building rules programmatically"],"tags":["jax","shardy","sharding-rule","typeerror"],"backgroundTag":"invalid-constructor-arguments","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}