def flatten_dtype(dtype, _next=None):
types = []<EOL>if _next is None: <EOL><INDENT>_next = [<NUM_LIT:0>, '<STR_LIT>']<EOL>primary = True<EOL><DEDENT>else:<EOL><INDENT>primary = False<EOL><DEDENT>prefix = _next[<NUM_LIT:1>]<EOL>if dtype.names is None:<EOL><INDENT>for i in numpy.ndindex(dtype.shape):<EOL><INDENT>if dtype.base == dtype:<EOL><INDENT>types.append(('<STR_LIT>' % (prefix, simplerepr(i)), dtype))<EOL>_next[<NUM_LIT:0>] += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>_next[<NUM_LIT:1>] = '<STR_LIT>' % (prefix, simplerepr(i))<EOL>types.extend(flatten_dtype(dtype.base, _next))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for field in dtype.names:<EOL><INDENT>typ_fields = dtype.fields[field]<EOL>if len(prefix) > <NUM_LIT:0>:<EOL><INDENT>_next[<NUM_LIT:1>] = prefix + '<STR_LIT:.>' + field<EOL><DEDENT>else:<EOL><INDENT>_next[<NUM_LIT:1>] = '<STR_LIT>' + field<EOL><DEDENT>flat_dt = flatten_dtype(typ_fields[<NUM_LIT:0>], _next)<EOL>types.extend(flat_dt)<EOL><DEDENT><DEDENT>_next[<NUM_LIT:1>] = prefix<EOL>if primary:<EOL><INDENT>return numpy.dtype(types)<EOL><DEDENT>else:<EOL><INDENT>return types<EOL><DEDENT>
Unpack a structured data-type.