import inspect
import sys
import types

from rmake.lib.apiutils import thaw, freeze

class NodeType(object):
    nodeType = 'UNKNOWN'
    def __init__(self):
        pass

    def freeze(self):
        return (self.nodeType, self.__dict__)

    @classmethod
    def thaw(class_, d):
        return class_(**d)

class Client(NodeType):
    nodeType = 'CLIENT'

_nodeTypes = {}
def registerNodeTypes(moduleName):
    global _nodeTypes
    for item in sys.modules[moduleName].__dict__.values():
        if inspect.isclass(item) and issubclass(item, NodeType):
            _nodeTypes[item.nodeType] = item
registerNodeTypes(__name__)

def registerNodeType(class_):
    _nodeTypes[class_.nodeType] = class_

def thawNodeType(info):
    nodeType = info[0]
    return _nodeTypes[nodeType].thaw(info[1])

import inspect
import sys
import types

from rmake.lib.apiutils import thaw, freeze


_nodeTypes = {}
class _NodeTypeRegistrar(type):
    def __init__(self, name, bases, dict):
        type.__init__(self, name, bases, dict)
        _nodeTypes[self.nodeType] = self


class NodeType(object):
    __metaclass__ = _NodeTypeRegistrar
    nodeType = 'UNKNOWN'
    def __init__(self):
        pass

    def freeze(self):
        return (self.nodeType, self.__dict__)

    @classmethod
    def thaw(class_, d):
        return class_(**d)

class Client(NodeType):
    nodeType = 'CLIENT'

def thawNodeType(info):
    nodeType = info[0]
    return _nodeTypes[nodeType].thaw(info[1])

Use metaclasses to register node types.
Use metaclasses to register node types.

  import inspect
  import sys
  import types
  
  from rmake.lib.apiutils import thaw, freeze
  
+ 
+ _nodeTypes = {}
+ class _NodeTypeRegistrar(type):
+     def __init__(self, name, bases, dict):
+         type.__init__(self, name, bases, dict)
+         _nodeTypes[self.nodeType] = self
+ 
+ 
  class NodeType(object):
+     __metaclass__ = _NodeTypeRegistrar
      nodeType = 'UNKNOWN'
      def __init__(self):
          pass
  
      def freeze(self):
          return (self.nodeType, self.__dict__)
  
      @classmethod
      def thaw(class_, d):
          return class_(**d)
  
  class Client(NodeType):
      nodeType = 'CLIENT'
  
- _nodeTypes = {}
- def registerNodeTypes(moduleName):
-     global _nodeTypes
-     for item in sys.modules[moduleName].__dict__.values():
-         if inspect.isclass(item) and issubclass(item, NodeType):
-             _nodeTypes[item.nodeType] = item
- registerNodeTypes(__name__)
- 
- def registerNodeType(class_):
-     _nodeTypes[class_.nodeType] = class_
- 
  def thawNodeType(info):
      nodeType = info[0]
      return _nodeTypes[nodeType].thaw(info[1])
  
Use metaclasses to register node types.
## Code Before:
import inspect
import sys
import types

from rmake.lib.apiutils import thaw, freeze

class NodeType(object):
    nodeType = 'UNKNOWN'
    def __init__(self):
        pass

    def freeze(self):
        return (self.nodeType, self.__dict__)

    @classmethod
    def thaw(class_, d):
        return class_(**d)

class Client(NodeType):
    nodeType = 'CLIENT'

_nodeTypes = {}
def registerNodeTypes(moduleName):
    global _nodeTypes
    for item in sys.modules[moduleName].__dict__.values():
        if inspect.isclass(item) and issubclass(item, NodeType):
            _nodeTypes[item.nodeType] = item
registerNodeTypes(__name__)

def registerNodeType(class_):
    _nodeTypes[class_.nodeType] = class_

def thawNodeType(info):
    nodeType = info[0]
    return _nodeTypes[nodeType].thaw(info[1])

## Instruction:
Use metaclasses to register node types.
## Code After:
import inspect
import sys
import types

from rmake.lib.apiutils import thaw, freeze


_nodeTypes = {}
class _NodeTypeRegistrar(type):
    def __init__(self, name, bases, dict):
        type.__init__(self, name, bases, dict)
        _nodeTypes[self.nodeType] = self


class NodeType(object):
    __metaclass__ = _NodeTypeRegistrar
    nodeType = 'UNKNOWN'
    def __init__(self):
        pass

    def freeze(self):
        return (self.nodeType, self.__dict__)

    @classmethod
    def thaw(class_, d):
        return class_(**d)

class Client(NodeType):
    nodeType = 'CLIENT'

def thawNodeType(info):
    nodeType = info[0]
    return _nodeTypes[nodeType].thaw(info[1])
