MCPcopy Index your code
hub / github.com/python/cpython / Field

Class Field

Lib/dataclasses.py:279–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277# When cls._FIELDS is filled in with a list of Field objects, the name
278# and type fields will have been populated.
279class Field:
280 __slots__ = ('name',
281 'type',
282 'default',
283 'default_factory',
284 'repr',
285 'hash',
286 'init',
287 'compare',
288 'metadata',
289 'kw_only',
290 'doc',
291 '_field_type', # Private: not to be used by user code.
292 )
293
294 def __init__(self, default, default_factory, init, repr, hash, compare,
295 metadata, kw_only, doc):
296 self.name = None
297 self.type = None
298 self.default = default
299 self.default_factory = default_factory
300 self.init = init
301 self.repr = repr
302 self.hash = hash
303 self.compare = compare
304 self.metadata = (_EMPTY_METADATA
305 if metadata is None else
306 types.MappingProxyType(metadata))
307 self.kw_only = kw_only
308 self.doc = doc
309 self._field_type = None
310
311 @recursive_repr()
312 def __repr__(self):
313 return ('Field('
314 f'name={self.name!r},'
315 f'type={self.type!r},'
316 f'default={self.default!r},'
317 f'default_factory={self.default_factory!r},'
318 f'init={self.init!r},'
319 f'repr={self.repr!r},'
320 f'hash={self.hash!r},'
321 f'compare={self.compare!r},'
322 f'metadata={self.metadata!r},'
323 f'kw_only={self.kw_only!r},'
324 f'doc={self.doc!r},'
325 f'_field_type={self._field_type}'
326 ')')
327
328 # This is used to support the PEP 487 __set_name__ protocol in the
329 # case where we're using a field that contains a descriptor as a
330 # default value. For details on __set_name__, see
331 # https://peps.python.org/pep-0487/#implementation-details.
332 #
333 # Note that in _process_class, this Field object is overwritten
334 # with the default value, so the end result is a descriptor that
335 # had __set_name__ called on it at the right time.
336 def __set_name__(self, owner, name):

Callers 1

fieldFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…