def fake_class(name_or_class_obj, members=()): if isinstance(name_or_class_obj, scoped_nodes.Class): cl = name_or_class_obj else: cl = scoped_nodes.Class(name_or_class_obj, None) for m in members: if isinstance(m, str): if m in cl.locals: _warning_already_exists(cl, m) else: cl.locals[m] = [scoped_nodes.Class(m, None)] elif isinstance(m, dict): for key, val in m.items(): assert isinstance(key, str), "key must be string" if key in cl.locals: _warning_already_exists(cl, key) fake_class(cl.locals[key], val) else: cl.locals[key] = [fake_class(key, val)] else: # here can be used any astroid type if m.name in cl.locals: _warning_already_exists(cl, m.name) else: cl.locals[m.name] = [copy.copy(m)] return cl
def transform(modu): if modu.name == 'google.appengine.ext.ndb': for f in [f for f in ndb.__dict__.keys() if 'Property' in f]: modu.locals[f] = [scoped_nodes.Class(f, None)] if modu.name == 'google.appengine.api.memcache': for f in memcache.__dict__.keys(): modu.locals[f] = [scoped_nodes.Class(f, None)]
def transform(cls): if cls.name in CLASS_NAME_BLACKLIST: return if cls.name.endswith('DB'): # mongoengine explicitly declared "id" field on each class so we teach pylint about that property_name = 'id' node = scoped_nodes.Class(property_name, None) cls.locals[property_name] = [node]
def transform(cls): """ pylint fails to "inherit" the attributes from the OrderedDict class when using multiple inheritance. So we need this fix for some special cases :param cls: The class, with name, etc. :return: None """ if cls.name in NEED_FIX: for f in FIX_MEMBERS: cls.locals[f] = [scoped_nodes.Class(f, None)]
def transform(cls, constants=None, functions=None): """ Transforms class objects from pylint so they're aware of extra attributes that are not present when being statically analyzed. """ assert isinstance(constants, set) assert isinstance(functions, set) for value in constants: cls.locals[value] = [scoped_nodes.Class(value, None)] for value in functions: cls.locals[value] = [scoped_nodes.Function(value, None)]
def transform(cls): if cls.name in CLASS_NAME_BLACKLIST: return if cls.name == 'StormFoundationDB': # _fields get added automagically by mongoengine if '_fields' not in cls.locals: cls.locals['_fields'] = [nodes.Dict()] if cls.name.endswith('DB'): # mongoengine explicitly declared "id" field on each class so we teach pylint about that property_name = 'id' node = scoped_nodes.Class(property_name, None) cls.locals[property_name] = [node]
def transform(cls): if cls.name in CLASS_NAME_BLACKLIST: return if cls.name.endswith('API') or 'schema' in cls.locals: # This is a class which defines attributes in "schema" variable using json schema. # Those attributes are then assigned during run time inside the constructor fqdn = cls.qname() module_name, class_name = fqdn.rsplit('.', 1) module = __import__(module_name, fromlist=[class_name]) actual_cls = getattr(module, class_name) schema = actual_cls.schema if not isinstance(schema, dict): # Not a class we are interested in return properties = schema.get('properties', {}) for property_name, property_data in six.iteritems(properties): property_name = property_name.replace( '-', '_') # Note: We do the same in Python code property_type = property_data.get('type', None) if isinstance(property_type, (list, tuple)): # Hack for attributes with multiple types (e.g. string, null) property_type = property_type[0] if property_type == 'object': node = nodes.Dict() elif property_type == 'array': node = nodes.List() elif property_type == 'integer': node = scoped_nodes.builtin_lookup('int')[1][0] elif property_type == 'number': node = scoped_nodes.builtin_lookup('float')[1][0] elif property_type == 'string': node = scoped_nodes.builtin_lookup('str')[1][0] elif property_type == 'boolean': node = scoped_nodes.builtin_lookup('bool')[1][0] elif property_type == 'null': node = scoped_nodes.builtin_lookup('None')[1][0] else: # Unknown type node = scoped_nodes.Class(property_name, None) cls.locals[property_name] = [node]
def transform(cls): if cls.name.endswith('API') or 'schema' in cls.locals: # This is a class which defines attributes in "schema" variable using json schema. # Those attributes are then assigned during run time inside the constructor fqdn = cls.qname() module_name, class_name = fqdn.rsplit('.', 1) module = __import__(module_name, fromlist=[class_name]) actual_cls = getattr(module, class_name) schema = actual_cls.schema if not isinstance(schema, dict): # Not a class we are interested in return properties = schema.get('properties', {}).keys() for property_name in properties: cls.locals[property_name] = [scoped_nodes.Class(property_name, None)]
def transform(cls): missing_members = CLASS_NO_MEMBERS.get(cls.name, []) for f in missing_members: cls.locals[f] = [scoped_nodes.Class(f, None)]
def transform(cls): """ Stop pylint from complaining about cs50.SQL """ if cls.name == 'cs50': import cs50 cls.locals["SQL"] = [scoped_nodes.Class("SQL", None)]