MCPcopy Create free account
hub / github.com/fabioz/PyDev.Debugger / SetResolver

Class SetResolver

_pydevd_bundle/pydevd_resolver.py:539–607  ·  view source on GitHub ↗

Resolves a set as dict id(object)->object

Source from the content-addressed store, hash-verified

537# SetResolver
538# =======================================================================================================================
539class SetResolver:
540 """
541 Resolves a set as dict id(object)->object
542 """
543
544 def get_contents_debug_adapter_protocol(self, obj, fmt=None):
545 ret = []
546
547 for i, item in enumerate(obj):
548 ret.append((str(id(item)), item, None))
549
550 if i >= pydevd_constants.PYDEVD_CONTAINER_RANDOM_ACCESS_MAX_ITEMS:
551 ret.append((TOO_LARGE_ATTR, TOO_LARGE_MSG % (pydevd_constants.PYDEVD_CONTAINER_RANDOM_ACCESS_MAX_ITEMS,), None))
552 break
553
554 # Needed in case the class extends the built-in type and has some additional fields.
555 from_default_resolver = defaultResolver.get_contents_debug_adapter_protocol(obj, fmt=fmt)
556 if from_default_resolver:
557 ret = from_default_resolver + ret
558 ret.append((GENERATED_LEN_ATTR_NAME, len(obj), partial(_apply_evaluate_name, evaluate_name="len(%s)")))
559 return ret
560
561 def resolve(self, var, attribute):
562 if attribute in (GENERATED_LEN_ATTR_NAME, TOO_LARGE_ATTR):
563 return None
564
565 try:
566 attribute = int(attribute)
567 except:
568 return getattr(var, attribute)
569
570 for v in var:
571 if id(v) == attribute:
572 return v
573
574 raise UnableToResolveVariableException("Unable to resolve %s in %s" % (attribute, var))
575
576 def get_dictionary(self, var):
577 d = {}
578 for i, item in enumerate(var):
579 d[str(id(item))] = item
580
581 if i >= pydevd_constants.PYDEVD_CONTAINER_RANDOM_ACCESS_MAX_ITEMS:
582 d[TOO_LARGE_ATTR] = TOO_LARGE_MSG % (pydevd_constants.PYDEVD_CONTAINER_RANDOM_ACCESS_MAX_ITEMS,)
583 break
584
585 # in case if the class extends built-in type and has some additional fields
586 additional_fields = defaultResolver.get_dictionary(var)
587 d.update(additional_fields)
588 d[GENERATED_LEN_ATTR_NAME] = len(var)
589 return d
590
591 def change_var_from_name(self, container, name, new_value):
592 # The name given in this case must be the id(item), so, we can actually
593 # iterate in the set and see which item matches the given id.
594
595 try:
596 # Check that the new value can actually be added to a set (i.e.: it's hashable/comparable).

Callers 1

pydevd_resolver.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected