def envvar_profile_cls(profile_cls=None, **profile_cls_options) -> typing.Type[EnvvarProfile]:
    """
    A class decorator that makes the decorated class a sub-class of EnvvarProfile and transforms
    its type annotations into envvar profile properties.
    """

    def decorator(profile_cls):
        profile_option_names = ["profile_root", "profile_activating_envvar"]
        profile_option_defaults = {
            "profile_root": to_snake_case(profile_cls.__name__)
        }

        dct = {}
        for option_name in profile_option_names:
            if option_name in profile_cls_options:
                dct[option_name] = profile_cls_options[option_name]
            elif option_name in profile_cls.__dict__:
                dct[option_name] = getattr(profile_cls, option_name)
            elif option_name in profile_option_defaults:
                dct[option_name] = profile_option_defaults[option_name]

        property_names = []

        for cls in reversed(profile_cls.__mro__[:-1]):
            # Exclude base classes that aren't SimpleProfile sub-classes or aren't the class being decorated.
            if not issubclass(cls, EnvvarProfile) and cls is not profile_cls:
                continue

            for k, v in typing.get_type_hints(cls).items():
                if k.startswith("_") or k.startswith("profile_"):
                    continue

                if k not in property_names:
                    property_names.append(k)

                default = getattr(cls, k, None)
                if isinstance(default, EnvvarProfileProperty):
                    default = default.default

                dct[k] = EnvvarProfileProperty(name=k, default=default, type_=v)

        dct["profile_properties"] = property_names

        bases = []
        if not issubclass(profile_cls, EnvvarProfile):
            bases.append(EnvvarProfile)
        bases.append(profile_cls)

        cls = type(profile_cls.__name__, tuple(bases), dct)
        cls.__qualname__ = profile_cls.__qualname__
        return cls

    if profile_cls is None:
        return decorator
    else:
        return decorator(profile_cls)
def envvar_profile_cls ( profile_cls = None , ** profile_cls_options ) -> typing . Type [ EnvvarProfile ] : def decorator ( profile_cls ) : profile_option_names = [ "profile_root" , "profile_activating_envvar" ] profile_option_defaults = { "profile_root" : to_snake_case ( profile_cls . __name__ ) } dct = { } for option_name in profile_option_names : if option_name in profile_cls_options : dct [ option_name ] = profile_cls_options [ option_name ] elif option_name in profile_cls . __dict__ : dct [ option_name ] = getattr ( profile_cls , option_name ) elif option_name in profile_option_defaults : dct [ option_name ] = profile_option_defaults [ option_name ] property_names = [ ] for cls in reversed ( profile_cls . __mro__ [ : - 1 ] ) : if not issubclass ( cls , EnvvarProfile ) and cls is not profile_cls : continue for k , v in typing . get_type_hints ( cls ) . items ( ) : if k . startswith ( "_" ) or k . startswith ( "profile_" ) : continue if k not in property_names : property_names . append ( k ) default = getattr ( cls , k , None ) if isinstance ( default , EnvvarProfileProperty ) : default = default . default dct [ k ] = EnvvarProfileProperty ( name = k , default = default , type_ = v ) dct [ "profile_properties" ] = property_names bases = [ ] if not issubclass ( profile_cls , EnvvarProfile ) : bases . append ( EnvvarProfile ) bases . append ( profile_cls ) cls = type ( profile_cls . __name__ , tuple ( bases ) , dct ) cls . __qualname__ = profile_cls . __qualname__ return cls if profile_cls is None : return decorator else : return decorator ( profile_cls )
A class decorator that makes the decorated class a sub-class of EnvvarProfile and transforms
    its type annotations into envvar profile properties.