23ws-LLMcoder/LLMcoder-GitHub-Python-Mix-Direct
Dataset Card for LLMcoder-GitHub-Python-Mix-Direct Python target autocomplete suggestions in the format of conversations for OpenAI's fine-tuning. Dataset Details Dataset Description Curated by: [More Information Needed] Funded by [optional]: [More Information Needed] Shared by [optional]: [More Information Needed] Language(s) (NLP): [More Information Needed] License: [More Information Needed] Dataset Sources [optional] The data… See the full description on the dataset page: https://huggingface.co/datasets/23ws-LLMcoder/LLMcoder-GitHub-Python-Mix-Direct.
0216
1# composite fields. In the meantime we take this practical approach to2 # solve a regression on 1.6 when the reverse manager in hidden3 # (related_name ends with a '+'). Refs #21410.4 # The check for len(...) == 1 is a special case that allows the query5 # to be join-less and smaller. Refs #21760.6 if remote_field.is_hidden() or len(self.field.foreign_related_fields) == 1:7 query = {8 "%s__in"9 % related_field.name: {instance_attr(inst)[0] for inst in instances}10 }11 else:12 query = {"%s__in" % self.field.related_query_name(): instances}13 queryset = queryset.filter(**query)14 15 # Since we're going to assign directly in the cache,16 # we must manage the reverse relation cache manually.17 if not remote_field.multiple:18 for rel_obj in queryset:19 instance = instances_dict[rel_obj_attr(rel_obj)]20 remote_field.set_cached_value(rel_obj, instance)21 return (22 queryset,23 rel_obj_attr,24 instance_attr,25 True,26 self.field.get_cache_name(),27 False,28 )29 30 def get_object(self, instance):31 qs = self.get_queryset(instance=instance)32 # Assuming the database enforces foreign keys, this won't fail.33 return qs.get(self.field.get_reverse_related_filter(instance))34 35 def __get__(self, instance, cls=None):36 """37 Get the related instance through the forward relation.38 39 With the example above, when getting ``child.parent``:40 41 - ``self`` is the descriptor managing the ``parent`` attribute42 - ``instance`` is the ``child`` instance43 - ``cls`` is the ``Child`` class (we don't need it)44 """45 if instance is None:46 return self47 48 # The related instance is loaded from the database and then cached49 # by the field on the model instance state. It can also be pre-cached50 # by the reverse accessor (ReverseOneToOneDescriptor).51 try:52 rel_obj = self.field.get_cached_value(instance)53 except KeyError:54 has_value = None not in self.field.get_local_related_value(instance)55 ancestor_link = (56 instance._meta.get_ancestor_link(self.field.model)57 if has_value58 else None59 )60 if ancestor_link and ancestor_link.is_cached(instance):61 # An ancestor link will exist if this field is defined on a62 # multi-table inheritance parent of the instance's class.63 ancestor = ancestor_link.get_cached_value(instance)64 # The value might be cached on an ancestor if the instance65 # originated from walking down the inheritance chain.66 rel_obj = self.field.get_cached_value(ancestor, default=None)67 else:68 rel_obj = None69 if rel_obj is None and has_value:70 rel_obj = self.get_object(instance)71 remote_field = self.field.remote_field72 # If this is a one-to-one relation, set the reverse accessor73 # cache on the related object to the current instance to avoid74 # an extra SQL query if it's accessed later on.75 if not remote_field.multiple:76 remote_field.set_cached_value(rel_obj, instance)77 self.field.set_cached_value(instance, rel_obj)78 79 if rel_obj is None and not self.field.null:80 raise self.RelatedObjectDoesNotExist(81 "%s has no %s." % (self.field.model.__name__, self.field.name)82 )83 else:84 return rel_obj85 86 def __set__(self, instance, value):87 """88 Set the related instance through the forward relation.89 90 With the example above, when setting ``child.parent = parent``:91 92 - ``self`` is the descriptor managing the ``parent`` attribute93 - ``instance`` is the ``child`` instance94 - ``value`` is the ``parent`` instance on the right of the equal sign95 """96 # An object must be an instance of the related class.97 if value is not None and not isinstance(98 value, self.field.remote_field.model._meta.concrete_model99 ):100 raise ValueError(101 'Cannot assign "%r": "%s.%s" must be a "%s" instance.'102 % (103 value,104 instance._meta.object_name,105 self.field.name,106 self.field.remote_field.model._meta.object_name,107 )108 )109 elif value is not None:110 if instance._state.db is None:111 instance._state.db = router.db_for_write(112 instance.__class__, instance=value113 )114 if value._state.db is None:115 value._state.db = router.db_for_write(116 value.__class__, instance=instance117 )118 if not router.allow_relation(value, instance):119 raise ValueError(120 'Cannot assign "%r": the current database router prevents this '121 "relation." % value122 )123 124 remote_field = self.field.remote_field125 # If we're setting the value of a OneToOneField to None, we need to clear126 # out the cache on any old related object. Otherwise, deleting the127 # previously-related object will also cause this object to be deleted,128 # which is wrong.129 if value is None:130 # Look up the previously-related object, which may still be available131 # since we've not yet cleared out the related field.132 # Use the cache directly, instead of the accessor; if we haven't133 # populated the cache, then we don't care - we're only accessing134 # the object to invalidate the accessor cache, so there's no135 # need to populate the cache just to expire it again.136 related = self.field.get_cached_value(instance, default=None)137 138 # If we've got an old related object, we need to clear out its139 # cache. This cache also might not exist if the related object140 # hasn't been accessed yet.141 if related is not None:142 remote_field.set_cached_value(related, None)143 144 for lh_field, rh_field in self.field.related_fields:145 setattr(instance, lh_field.attname, None)146 147 # Set the values of the related field.148 else:149 for lh_field, rh_field in self.field.related_fields:150 setattr(instance, lh_field.attname, getattr(value, rh_field.attname))151 152 # Set the related instance cache used by __get__ to avoid an SQL query153 # when accessing the attribute we just set.154 self.field.set_cached_value(instance, value)155 156 # If this is a one-to-one relation, set the reverse accessor cache on157 # the related object to the current instance to avoid an extra SQL158 # query if it's accessed later on.159 if value is not None and not remote_field.multiple:160 remote_field.set_cached_value(value, instance)161 162 def __reduce__(self):163 """164 Pickling should return the instance attached by self.field on the165 model, not a new copy of that descriptor. Use getattr() to retrieve166 the instance directly from the model.167 """168 return getattr, (self.field.model, self.field.name)169 170 171class ForwardOneToOneDescriptor(ForwardManyToOneDescriptor):172 """173 Accessor to the related object on the forward side of a one-to-one relation.174 175 In the example::176 177 class Restaurant(Model):178 place = OneToOneField(Place, related_name='restaurant')179 180 ``Res