MCPcopy
hub / github.com/python-attrs/attrs / has

Function has

src/attr/_funcs.py:354–379  ·  src/attr/_funcs.py::has

Check whether *cls* is a class with *attrs* attributes. Args: cls (type): Class to introspect. Raises: TypeError: If *cls* is not a class. Returns: bool:

(cls)

Source from the content-addressed store, hash-verified

352
353
354def has(cls):
355 class="st">"""
356 Check whether *cls* is a class with *attrs* attributes.
357
358 Args:
359 cls (type): Class to introspect.
360
361 Raises:
362 TypeError: If *cls* is not a class.
363
364 Returns:
365 bool:
366 class="st">"""
367 attrs = getattr(cls, class="st">"__attrs_attrs__", None)
368 if attrs is not None:
369 return True
370
371 class="cm"># No attrs, maybe it's a specialized generic (A[str])?
372 generic_base = get_generic_base(cls)
373 if generic_base is not None:
374 generic_attrs = getattr(generic_base, class="st">"__attrs_attrs__", None)
375 if generic_attrs is not None:
376 class="cm"># Stick it on here for speed next time.
377 cls.__attrs_attrs__ = generic_attrs
378 return generic_attrs is not None
379 return False
380
381
382def assoc(inst, **changes):

Callers 11

test_hashabilityFunction · 0.90
test_positiveMethod · 0.90
test_positive_emptyMethod · 0.90
test_negativeMethod · 0.90
test_genericsMethod · 0.90
asdictFunction · 0.85
astupleFunction · 0.85

Calls 1

get_generic_baseFunction · 0.85

Tested by 9

test_hashabilityFunction · 0.72
test_positiveMethod · 0.72
test_positive_emptyMethod · 0.72
test_negativeMethod · 0.72
test_genericsMethod · 0.72