Dynamically building outputspec class

I am building a custom interface and having some trouble to build the outputspec. My idea is I wanted to build the outputspec dynamically from a dictionary. So if the dictionary has key A, B and C, I wanted the output to be A, B and C. However, I am stuck on setting the attribute for the outputsepc as the attribute needs to be traits.Str() or any traits object (if I understand correctly). Would really appreciate if someone can give me some advice on what I need to do.

Below is what I have so far.

class CustomInterfaceA(SimpleInterface):
    def _outputspec_build(dict_a):
        outputSpec_A = type("outputSpecA", (TraitedSpec, ), {})
        for k in dict_a.keys():
            setattr(outputSpec_A, k, traits.Str())
        return outputSpec_A

    def __init__(self, dict_a):
        self.outputspec = self._outputspec_build(dict_a)

   def _run_interface(self, runtime):

And here is what I ran into when I tried to do run()

test_node = CustomInterfaceA(dict_a)




>>> AttributeError: 'NoneType' object has no attribute 'trait_names'

Any idea what I need to fix to make this work?