Adds class methods from modifier_class to original_class.
    If override is True existing methods in original_class are overriden by those provided by modifier_class.
768016
def modify_class(original_class, modifier_class, override=True):
    
    # get members to add
    modifier_methods = inspect.getmembers(modifier_class, inspect.ismethod)
    
    # set methods
    for method_tuple in modifier_methods:
        name = method_tuple[0]
        method = method_tuple[1]
        if isinstance(method, types.UnboundMethodType):
            if hasattr(original_class, name) and not override:
                return None
            else:
                setattr(original_class, name, method.im_func)
1016404
def _add_dunder_class(func, member):
    """"""
    python_cls = member.__class__
    cls_name = getattr(python_cls, "__name__", None)
    if not cls_name:
        return
    cls_bases = [ancestor.__name__ for ancestor in python_cls.__bases__]
    ast_klass = build_class(cls_name, cls_bases, python_cls.__doc__)
    func.instance_attrs["__class__"] = [ast_klass]
1182867
def add_new_repr_method(cls):
    

    if isinstance(cls.__repr__, WrapperDescriptorType):
        cls.__repr__ = lambda self: f"<{self.__class__.__name__}, id={hex(id(self))}>"
    else:
        # Keep the user-defined __repr__ method
        pass
314539
def modify_classes():
    
    import copy
    from django.conf import settings
    from django.contrib.admin.sites import site
    from django.utils.importlib import import_module
    from django.utils.module_loading import module_has_submodule

    for app in settings.INSTALLED_APPS:
        mod = import_module(app)
        # Attempt to import the app's class_modifier module.
        try:
            before_import_registry = copy.copy(site._registry)
            import_module('%s.class_modifiers' % app)
        except:
            site._registry = before_import_registry
            # Decide whether to bubble up this error. If the app just
            # doesn't have an class_modifier module, we can ignore the error
            # attempting to import it, otherwise we want it to bubble up.
            if module_has_submodule(mod, 'class_modifiers'):
                raise
1117426
public static MethodNode addGeneratedMethod(ClassNode cNode, String name,
                                int modifiers,
                                ClassNode returnType,
                                Parameter[] parameters,
                                ClassNode[] exceptions,
                                Statement code) {
        MethodNode result = cNode.addMethod(name, modifiers, returnType, parameters, exceptions, code);
        markAsGenerated(cNode, result);
        return result;
    }
31402
def _validate_method_decoration(meta, class_):
        
        # TODO(xion): employ some code inspection tricks to serve ClassErrors
        # as if they were thrown at the offending class's/method's definition

        super_mro = class_.__mro__[1:]
        own_methods = ((name, member)
                       for name, member in class_.__dict__.items()
                       if is_method(member))

        # check that ``@override`` modifier is present where it should be
        # and absent where it shouldn't (e.g. ``@final`` methods)
        for name, method in own_methods:
            shadowed_method, base_class = next(
                ((getattr(base, name), base)
                 for base in super_mro if hasattr(base, name)),
                (None, None)
            )
            if meta._is_override(method):
                # ``@override`` is legal only when the method actually shadows
                # a method from a superclass, and that metod is not ``@final``
                if not shadowed_method:
                    raise ClassError("unnecessary @override on %s.%s" % (
                        class_.__name__, name), class_=class_)
                if meta._is_final(shadowed_method):
                    raise ClassError(
                        "illegal @override on a @final method %s.%s" % (
                            base_class.__name__, name), class_=class_)

                # if @override had parameter supplied, verify if it was
                # the same class as the base of shadowed method
                override_base = meta._get_override_base(method)
                if override_base and base_class is not override_base:
                    if is_class(override_base):
                        raise ClassError(
                            "incorrect override base: expected %s, got %s" % (
                                base_class.__name__, override_base.__name__))
                    else:
                        raise ClassError(
                            "invalid override base specified: %s" % (
                                override_base,))

                setattr(class_, name, method.method)
            else:
                if shadowed_method and name not in meta.OVERRIDE_EXEMPTIONS:
                    if meta._is_final(shadowed_method):
                        msg = "%s.%s is hiding a @final method %s.%s" % (
                            class_.__name__, name, base_class.__name__, name)
                    else:
                        msg = ("overridden method %s.%s "
                               "must be marked with @override" % (
                                class_.__name__, name))
                    raise ClassError(msg, class_=class_)
1172391
def method_added(method_name)
      # do nothing if the method that was added was an actual hook method, or
      # if it already had hooks added to it
      return if hooks.include?(method_name) || hooked_methods.include?(method_name)
      add_hooks_to(method_name)
    end
150253
def add_flex_arithmetic_methods(cls):
    
    flex_arith_method, flex_comp_method, _, _, _ = _get_method_wrappers(cls)
    new_methods = _create_methods(cls, flex_arith_method,
                                  flex_comp_method, bool_method=None,
                                  special=False)
    new_methods.update(dict(multiply=new_methods['mul'],
                            subtract=new_methods['sub'],
                            divide=new_methods['div']))
    # opt out of bool flex methods for now
    assert not any(kname in new_methods for kname in ('ror_', 'rxor', 'rand_'))

    add_methods(cls, new_methods=new_methods)
1254731
public function addMethod(Method $method, $override = false) {
        $methods = $this->getMethods();
        $key = $method->getName();
        if(array_key_exists($key, $methods) && !$override) {
            throw new \Exception('A Method with the name of: ' . $method->getName() . ' already exists');
        }
        $methods[$key] = $method;
        ksort($methods);
        $this->setMethods($methods);
    }
284382
private void addHashCodeMethod() {
        Modifiers modifiers = Modifiers.PUBLIC.toSynchronized(true);
        MethodInfo mi = addMethodIfNotFinal(modifiers, "hashCode", TypeDesc.INT, null);

        if (mi == null) {
            return;
        }

        CodeBuilder b = new CodeBuilder(mi);

        boolean mixIn = false;
        for (StorableProperty property : mAllProperties.values()) {
            if (property.isDerived() || property.isJoin()) {
                continue;
            }
            TypeDesc fieldType = TypeDesc.forClass(property.getType());
            b.loadThis();
            b.loadField(property.getName(), fieldType);
            CodeBuilderUtil.addValueHashCodeCall(b, fieldType, true, mixIn);
            mixIn = true;
        }

        b.returnValue(TypeDesc.INT);
    }
983271
def _may_override(self, implem, other):
        """"""
        if isinstance(other, ImplementationProperty):
            # Overriding another custom implementation for the same transition
            # and field
            return (other.transition == implem.transition and other.field_name == self.state_field)

        elif isinstance(other, TransitionWrapper):
            # Overriding the definition that led to adding the current
            # ImplementationProperty.
            return (
                other.trname == implem.transition.name
                and (not other.field or other.field == self.state_field)
                and other.func == implem.implementation)

        return False
886725
def extend(instance, new_class):
    
    instance.__class__ = type(
        '%s_extended_with_%s' % (instance.__class__.__name__, new_class.__name__),
        (new_class, instance.__class__,),
        {}
    )
1348530
def add_class(self, cls, callback):
        
        if cls.TAG in self._tag_map:
            raise ValueError(
                "duplicate tag: {!r} is already handled by {}".format(
                    cls.TAG,
                    self._tag_map[cls.TAG]))
        self._class_map[cls] = callback
        self._tag_map[cls.TAG] = (cls, callback)
248259
def statusable_methods
      # Include generated methods with a module, not right in class.
      @statusable_methods ||= Module.new.tap do |m|
        m.const_set :ClassMethods, Module.new
        include m
        extend m::ClassMethods
      end
    end
961457
private boolean overridingMethodFound(ExecutableElement method) {
        TypeElement containingClass = utils.getEnclosingTypeElement(method);
        for (ExecutableElement listmethod : methlist) {
            if (containingClass == utils.getEnclosingTypeElement(listmethod)) {
                // it's the same method.
                return true;
            }
            TypeElement te = utils.overriddenClass(listmethod);
            if (te == null) {
                continue;
            }
            if (te == containingClass || utils.isSubclassOf(te, containingClass)) {
                return true;
            }
        }
        return false;
    }
6084
def add_full_state_methods(class_with_globalize_methods):
    
    assert hasattr(class_with_globalize_methods, 'active_set')
    assert hasattr(class_with_globalize_methods, 'nstates_full')

    for name, method in class_with_globalize_methods.__dict__.copy().items():
        if isinstance(method, property) and hasattr(method.fget, '_map_to_full_state_def_arg'):
            default_value = method.fget._map_to_full_state_def_arg
            axis = method.fget._map_to_full_state_along_axis
            new_getter = _wrap_to_full_state(name, default_value, axis)
            alias_to_full_state_inst = property(new_getter)
        elif hasattr(method, '_map_to_full_state_def_arg'):
            default_value = method._map_to_full_state_def_arg
            axis = method._map_to_full_state_along_axis
            alias_to_full_state_inst = _wrap_to_full_state(name, default_value, axis)
        else:
            continue

        name += "_full_state"
        setattr(class_with_globalize_methods, name, alias_to_full_state_inst)

    return class_with_globalize_methods
424863
def apply(self, cls, originalMemberNameList, memberName, classNamingConvention, getter, setter):
        
        # The new property.
        originalProperty = None
        if memberName in originalMemberNameList:
            member = getattr(cls, memberName)
            
            # There's already a member with that name and it's not a property
            if not isinstance(member, property):
                raise InvalidPropertyOverrideError(memberName, cls.__name__)
            
            # If property already exists, we will just modify it.
            originalProperty = member
        
        kwargs = {self._KEY_PROPERTY_GET: getattr(originalProperty, self._KEY_PROPERTY_GET, None) or getter,
                  self._KEY_PROPERTY_SET: getattr(originalProperty, self._KEY_PROPERTY_SET, None) or setter,
                  self._KEY_PROPERTY_DEL: getattr(originalProperty, self._KEY_PROPERTY_DEL, None) or None,
                  self._KEY_PROPERTY_DOC: getattr(originalProperty, self._KEY_PROPERTY_DOC, None) or None}
        setattr(cls, memberName, property(**kwargs))