Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
816d3c6
Implement _AttrsParams
hynek Jul 31, 2025
ca2daab
Set __attrs_base_of_slotted__ for unused base classes
hynek Aug 5, 2025
bf85647
Rename to ClassProps
hynek Aug 10, 2025
026cd07
Start renaming fields so it's clearer these aren't just arguments
hynek Aug 10, 2025
98c09ab
Reorder
hynek Aug 10, 2025
c511679
Dont's expose has_custom_setattr
hynek Aug 10, 2025
2a750dc
Make KeywordOnly an Enum
hynek Sep 8, 2025
02f99a6
Make cache_hash part of the Hashability Enum
hynek Sep 8, 2025
2ee35c2
Add attrs.inspect()
hynek Sep 22, 2025
8d31828
Refactor enums into class since they're only used by that class
hynek Sep 23, 2025
cd7ec0d
Docs
hynek Sep 23, 2025
93a0b21
Move back, rip out type hints
hynek Sep 28, 2025
88c059b
Revert "Move back, rip out type hints"
hynek Sep 28, 2025
27bf9c2
Use internal mechanisms instead of NamedTuple
hynek Sep 28, 2025
6490c7b
Add news fragment
hynek Sep 28, 2025
516f090
Document it's experimental
hynek Sep 28, 2025
b5df8a5
Improve ClassProps documentation
hynek Sep 28, 2025
9e97757
Add type information to docs
hynek Sep 28, 2025
bbd5494
Improve field names
hynek Sep 28, 2025
4938e74
Avoid repeated attribute lookups
hynek Sep 28, 2025
32a5a7f
More more helpful field names
hynek Sep 28, 2025
e101e59
Add warning to class too
hynek Sep 28, 2025
17393c7
Add explanation
hynek Sep 28, 2025
e9f52c0
Add to changelog, too
hynek Sep 28, 2025
48cb42f
Nicer phrasing
hynek Sep 28, 2025
8d45a66
Grammar
hynek Sep 28, 2025
1c9c2bb
docs
hynek Sep 28, 2025
1b7be61
Consistency
hynek Sep 28, 2025
dd11420
Make inspect/ClassProps NG-only
hynek Sep 28, 2025
f9ec63a
Remove stray empty line
hynek Sep 28, 2025
9d2cc65
Don't half-ass next_gen-ing
hynek Sep 28, 2025
94cbe7d
Avoid attribute lookups in hot loop
hynek Sep 28, 2025
b89ce95
Add field access type tests
hynek Sep 28, 2025
651c4c0
A docstring is not appropriate here
hynek Sep 28, 2025
5ff5807
Move typing example to baseline
hynek Sep 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.d/1454.change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Added a new **experimental** way to inspect classes:

`attrs.inspect(cls)` returns the _effective_ class-wide parameters that were used by *attrs* to construct the class.

The returned class is the same data structure that *attrs* uses internally to decide how to construct the final class.
18 changes: 18 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ Helpers
>>> attrs.has(object)
False

.. autofunction:: attrs.inspect

For example:

.. doctest::

>>> @define
... class CInspect:
... pass
>>> attrs.inspect(CInspect) # doctest: +ELLIPSIS
ClassProps(is_exception=False, is_slotted=True, has_weakref_slot=True, is_frozen=False, kw_only=<KeywordOnly.NO: 'no'>, collected_fields_by_mro=True, added_init=True, added_repr=True, added_eq=True, added_ordering=False, hashability=<Hashability.UNHASHABLE: 'unhashable'>, added_match_args=True, added_str=False, added_pickling=True, on_setattr_hook=<function pipe.<locals>.wrapped_pipe at ...>, field_transformer=None)

.. autoclass:: attrs.ClassProps
.. autoclass:: attrs.ClassProps.Hashability
:members: HASHABLE, HASHABLE_CACHED, UNHASHABLE, LEAVE_ALONE
.. autoclass:: attrs.ClassProps.KeywordOnly
:members: NO, YES, FORCE

.. autofunction:: attrs.resolve_types

For example:
Expand Down
2 changes: 1 addition & 1 deletion docs/how-does-it-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ No magic, no meta programming, no expensive introspection at runtime.
Everything until this point happens exactly *once* when the class is defined.
As soon as a class is done, it's done.
And it's just a regular Python class like any other, except for a single `__attrs_attrs__` attribute that *attrs* uses internally.
Much of the information is accessible via {func}`attrs.fields` and other functions which can be used for introspection or for writing your own tools and decorators on top of *attrs* (like {func}`attrs.asdict`).
Much of the information is accessible via {func}`attrs.inspect`, {func}`attrs.fields` and other functions which can be used for introspection or for writing your own tools and decorators on top of *attrs* (like {func}`attrs.asdict`).

And once you start instantiating your classes, *attrs* is out of your way completely.

Expand Down
Loading