Convenience method to set the __doc__ attribute of a python object
969513
def _set_object_doc(self, obj, doc, stacklevel=3):
        
        if isinstance(obj, types.MethodType) and six.PY2:
            obj = obj.im_func
        try:
            obj.__doc__ = doc
        except AttributeError:  # probably python2 class
            if (self.python2_classes != 'raise' and
                    (inspect.isclass(obj) and six.PY2)):
                if self.python2_classes == 'warn':
                    warn("Cannot modify docstring of classes in python2!",
                         stacklevel=stacklevel)
            else:
                raise
        return obj
368095
def set_attr(self):
        
        setattr(self.attrs, self.kind_attr, self.values)
        setattr(self.attrs, self.meta_attr, self.meta)
        if self.dtype is not None:
            setattr(self.attrs, self.dtype_attr, self.dtype)
1002242
def _setattr_default(obj, attr, value, default):
    """"""
    if value is None:
        setattr(obj, attr, default)
    else:
        setattr(obj, attr, value)
722038
def _setAttr(self, attr, value):
        
        meth = "_set_%s" % attr
        if not hasattr(self, meth):
            raise AttributeError("No setter for attribute '%s'." % attr)
        meth = getattr(self, meth)
        meth(value)
1294029
def _init_obj_attrs(self, obj, user=False):
        
        for attr in obj.__class__._tx_attrs.values():

            if user:
                # Mangle name to prvent name clashing
                attr_name = "_txa_%s" % attr.name
            else:
                attr_name = attr.name

            if attr.mult in [MULT_ZEROORMORE, MULT_ONEORMORE]:
                # list
                setattr(obj, attr_name, [])
            elif attr.cls.__name__ in BASE_TYPE_NAMES:
                # Instantiate base python type
                if self.auto_init_attributes:
                    setattr(obj, attr_name,
                            python_type(attr.cls.__name__)())
                else:
                    # See https://github.com/textX/textX/issues/11
                    if attr.bool_assignment:
                        # Only ?= assignments shall have default
                        # value of False.
                        setattr(obj, attr_name, False)
                    else:
                        # Set base type attribute to None initially
                        # in order to be able to detect if an optional
                        # values are given in the model. Default values
                        # can be specified using object processors.
                        setattr(obj, attr_name, None)
            else:
                # Reference to other obj
                setattr(obj, attr_name, None)
1051385
def _set_attribute(self, attribute, name, value):
        """"""
        try:
            if attribute is None:
                attribute = self._attribute_file_open( name )
            else:
                attribute.seek(0)

            if isinstance(value, str):
                value = value.encode()
            attribute.write(value)
            attribute.flush()
        except Exception as ex:
            self._raise_friendly_access_error(ex, name)
        return attribute
370627
def as_method(self, docstring=""):
        
        method = lambda obj, *args, **kwargs: self(obj, *args, **kwargs)
        if docstring:
            method.__doc__ = docstring
        return method
212247
def _update_docstrings(self):
        
        ops = self._details.resource_data['operations']

        for method_name in ops.keys():
            meth = getattr(self.__class__, method_name, None)

            if not meth:
                continue

            if meth.__doc__ != DEFAULT_DOCSTRING:
                # It already has a custom docstring. Leave it alone.
                continue

            # Needs updating. So there's at least *something* vaguely useful
            # there, use the docstring from the underlying ``Connection``
            # method.
            # FIXME: We need to figure out a way to make this more useful, if
            #        possible.
            api_name = ops[method_name]['api_name']
            conn_meth = getattr(self._connection, to_snake_case(api_name))

            # We need to do detection here, because Py2 treats ``.__doc__``
            # as a special read-only attribute. :/
            if six.PY3:
                meth.__doc__ = conn_meth.__doc__
            else:
                meth.__func__.__doc__ = conn_meth.__doc__
1091887
def set_attributes(self, doc, fields, parent_type=None):
        

        if parent_type:
            assert isinstance(parent_type, Struct)

        self.subtypes = []

        # These are only set if this struct enumerates subtypes.
        self._enumerated_subtypes = None  # Optional[List[Tuple[str, DataType]]]
        self._is_catch_all = None  # Optional[Bool]

        super(Struct, self).set_attributes(doc, fields, parent_type)

        if self.parent_type:
            self.parent_type.subtypes.append(self)
694038
def _docspec_comments(obj) -> Dict[str, str]:
    
    # Sometimes our docstring is on the class, and sometimes it's on the initializer,
    # so we've got to check both.
    class_docstring = getattr(obj, '__doc__', None)
    init_docstring = getattr(obj.__init__, '__doc__', None) if hasattr(obj, '__init__') else None

    docstring = class_docstring or init_docstring or ''

    doc = NumpyDocString(docstring)
    params = doc["Parameters"]
    comments: Dict[str, str] = {}

    for line in params:
        # It looks like when there's not a space after the parameter name,
        # numpydocstring parses it incorrectly.
        name_bad = line[0]
        name = name_bad.split(":")[0]

        # Sometimes the line has 3 fields, sometimes it has 4 fields.
        comment = "\n".join(line[-1])

        comments[name] = comment

    return comments
882456
def attr(cls, iterable, attr_name):
    

    return cls(getattr(x, attr_name) for x in iterable)
884523
def restore_attr(self, attr_name):
        
        original_attr = self._original_attr(attr_name)
        if self._original_attr(attr_name):
            setattr(self.obj.__class__, attr_name, original_attr)
615717
def _set_doc(self, func):
		
		if not self.doc and func.__doc__:
			self.doc = func.__doc__.strip().replace('\n', ' ')
318986
def _generic_dict_attribute(self, obj, name):
        """"""

        class DictMethodBoundMethod(astroid.BoundMethod):
            def infer_call_result(self, caller, context=None):
                yield obj

        meth = next(self._instance._proxied.igetattr(name))
        return DictMethodBoundMethod(proxy=meth, bound=self._instance)
260804
def _set_attr(self, name, doc=None, preload=False):
        ""

        if doc is None:
            doc = 'The {name} attribute.'.format(name=name)

        if not hasattr(self._attr_func_, name):
            attr_prop = property(
                functools.partial(self._setable_get_, name),
                functools.partial(self._setable_set_, name),
                doc=doc
            )

        elif preload:
            func = getattr(self._attr_func_, name)
            setattr(self._attr_data_, name, func())
            delattr(self._attr_func_, name)
            attr_prop = property(
                functools.partial(self._simple_get_, name),
                doc=doc
            )

        else:
            attr_prop = property(
                functools.partial(self._loadable_get_, name),
                doc=doc
            )

        setattr(type(self), name, attr_prop)
161380
def get_description(cls) -> str:
        
        if cls.__doc__ is None:
            raise ValueError('No docstring found for {}'.format(cls.__name__))
        return cls.__doc__.strip()
1057336
def get_attr(obj, string_rep, default=_get_attr_raise_on_attribute_error, separator="."):
    
    attribute_chain = string_rep.split(separator)

    current_obj = obj

    for attr in attribute_chain:
        try:
            current_obj = getattr(current_obj, attr)
        except AttributeError:
            if default is _get_attr_raise_on_attribute_error:
                raise AttributeError(
                    "Bad attribute \"{}\" in chain: \"{}\"".format(attr, string_rep)
                )
            return default

    return current_obj