title: metaclassing OrderdDict with fromkeys and Struct
body: <p>I'm new to metaprogramming in python. What I'd like to do something similar to the following:</p>
  
  <pre><code>from struct import Struct, error as StructError
  from collections import OrderedDict
  from typing import List, Hashable
  from uuid import UUID
  
  class StructBytes(type):
  
      def __prepare__(name, bases, **kwds):
          return OrderedDict()
  
      # return a subclass/modification of OrdereDict with predefined keys and a Struct(fmt)
      # __init__ should fill key values from Struct.unpack(bytes)
      # in principle (although not necessary), this is a frozen ordered dict
  
  ...
  
  class ThisFormat(metaclass=StructBytes, keys: List[Hashable], fmt: str)
  
      def __init__(some_bytes: bytes)
          try:
              # call to __init__ should use specified formatting
          except StructError:
              # some_bytes not valid for this class 
          else:
              # do post-processing on some field values, like:
              self['uuid'] = UUID(bytes=self['uuid'])
  
  for some_bytes in buffer:
      structured = ThisFormat(some_bytes)
      structured[field] # returns post-processed bytes
  </code></pre>
  
  <p>But at this point I'm not sure how to implement it. The reason I see for metaprogramming is that multiple versions of <code>ThisFormat</code> exist each with specific field keys and byte structure (i.e. format for Struct). Can anyone give me some pointers?</p>