985 })
986
987 def create_list_resolver(Model, mapper):
988 def resolver(parent, info, filters=None, lookups=None, sort=None, pagination=None, search=None): 989 request = info.context.get('request')
990
991 if before_resolve is not None:
856
857 i += 1
858
859 def resolve_model_list(self, MappedBase, Model, mapper,info, filters=None, lookups=None, sort=None, pagination=None, search=None): 860 try:
861 filters = filters or []
862 lookups = lookups or []
973 FiltersType = self.get_model_filters_type(MappedBase, mapper)
974 LookupsType = self.get_model_lookups_type(MappedBase, mapper)
975 SortType = self.get_model_sort_type(MappedBase, mapper)
976 ModelAttrsType = self.get_model_attrs_type(MappedBase, mapper) 977 ModelType = type('Model{}ModelType'.format(name), (graphene.ObjectType,), {
978 'attrs': graphene.Field(ModelAttrsType),
979 'allAttrs': graphene.Field(RawScalar),
439
440 return queryset
441
442 def get_models_lookups(self, request, MappedBase, models, Model, mapper, lookups): 443 result = []
444
445 for lookup_item in lookups:
357
358 type_code_to_sql_type = get_type_code_to_sql_type(request)
359 if type_code_to_sql_type:
360 def map_column_description(column):361 name = column.name if hasattr(column, 'name') else ''
362 sql_type = type_code_to_sql_type.get(column.type_code) if hasattr(column, 'type_code') else None
363 return name, {
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()