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

Function _is_class_var

src/attr/_make.py:294–308  ·  view source on GitHub ↗

Check whether *annot* is a typing.ClassVar. The string comparison hack is used to avoid evaluating all string annotations which would put attrs-based classes at a performance disadvantage compared to plain old classes.

(annot)

Source from the content-addressed store, hash-verified

292
293
294def _is_class_var(annot):
295 """
296 Check whether *annot* is a typing.ClassVar.
297
298 The string comparison hack is used to avoid evaluating all string
299 annotations which would put attrs-based classes at a performance
300 disadvantage compared to plain old classes.
301 """
302 annot = str(annot)
303
304 # Annotation can be quoted.
305 if annot.startswith(("'", '"')) and annot.endswith(("'", '"')):
306 annot = annot[1:-1]
307
308 return annot.startswith(_CLASSVAR_PREFIXES)
309
310
311def _has_own_attribute(cls, attrib_name):

Callers 2

test_is_class_varFunction · 0.90
_transform_attrsFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_is_class_varFunction · 0.72