@rbac(('owner', 'user'), proxy_types=[CTrait])
    def get_dyn_trait(self, pathname, iotype=None, trait=None):
        """Returns a trait if a trait with the given pathname exists, possibly
        creating it "on-the-fly" and adding its Container. If an attribute exists
        with the given pathname but no trait is found or can be created, or if
        pathname references a trait in a parent scope, None will be returned.
        If no attribute exists with the given pathname within this scope, an
        AttributeError will be raised.

        pathname: str
            Pathname of the desired trait.  May contain dots.

        iotype: str (optional)
            Expected iotype of the trait.

        trait: TraitType (optional)
            Trait to be used for validation.
        """
        if pathname.startswith('parent.'):
            return None
        cname, _, restofpath = pathname.partition('.')
        if restofpath:
            child = getattr(self, cname)
            if is_instance(child, Container):
                return child.get_dyn_trait(restofpath, iotype, trait)
            else:
                if deep_hasattr(child, restofpath):
                    return None
        else:
            trait = self.get_trait(cname)
            if trait is not None:
                if iotype is not None:
                    if isinstance(trait.trait_type, Python):  # VariableTree
                        obj = getattr(self, cname)
                        t_iotype = getattr(obj, 'iotype', None)
                    else:  # Variable
                        t_iotype = self.get_iotype(cname)
                    if (iotype == 'in' and t_iotype not in ('in', 'state')) or \
                       (iotype == 'out' and ('out', 'in', 'state', 'residual') not in t_iotype):
                        self.raise_exception("'%s' must be an %s variable" %
                                             (pathname, _iodict[iotype]),
                                             RuntimeError)
                return trait
            elif trait is None and self.contains(cname):
                return None

        self.raise_exception("Cannot locate variable named '%s'" %
                             pathname, AttributeError)
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.main/src/openmdao/main/container.py/Container.get_dyn_trait/swapped operands of `not in`