MCPcopy Index your code
hub / github.com/python/mypy / attr_class_maker_callback

Function attr_class_maker_callback

mypy/plugins/attrs.py:308–335  ·  view source on GitHub ↗

Add necessary dunder methods to classes decorated with attr.s. attrs is a package that lets you define classes without writing dull boilerplate code. At a quick glance, the decorator searches the class body for assignments of `attr.ib`s (or annotated variables if auto_attribs=True), th

(
    ctx: mypy.plugin.ClassDefContext,
    auto_attribs_default: bool | None = False,
    frozen_default: bool = False,
    slots_default: bool = False,
)

Source from the content-addressed store, hash-verified

306
307
308def attr_class_maker_callback(
309 ctx: mypy.plugin.ClassDefContext,
310 auto_attribs_default: bool | None = False,
311 frozen_default: bool = False,
312 slots_default: bool = False,
313) -> bool:
314 """Add necessary dunder methods to classes decorated with attr.s.
315
316 attrs is a package that lets you define classes without writing dull boilerplate code.
317
318 At a quick glance, the decorator searches the class body for assignments of `attr.ib`s (or
319 annotated variables if auto_attribs=True), then depending on how the decorator is called,
320 it will add an __init__ or all the compare methods.
321 For frozen=True it will turn the attrs into properties.
322
323 Hashability will be set according to https://www.attrs.org/en/stable/hashing.html.
324
325 See https://www.attrs.org/en/stable/how-does-it-work.html for information on how attrs works.
326
327 If this returns False, some required metadata was not ready yet, and we need another
328 pass.
329 """
330 with state.strict_optional_set(ctx.api.options.strict_optional):
331 # This hook is called during semantic analysis, but it uses a bunch of
332 # type-checking ops, so it needs the strict optional set properly.
333 return attr_class_maker_callback_impl(
334 ctx, auto_attribs_default, frozen_default, slots_default
335 )
336
337
338def attr_class_maker_callback_impl(

Callers

nothing calls this directly

Calls 2

strict_optional_setMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…