Open RNKuhns opened 7 months ago
Note that I'll also add examples to the docs before this is finalized/merged if the concept moves forward.
@hynek I know you are probably busy, but I just wanted to check in to see if you had a chance to take a look and provide feedback.
yeah sorry I'm swamped right now, as you can tell in my own PR #1267 that hasn't moved in a while. I don't have the headspace for bigger changes right now, but it won't get lost as long as you leave it open. I hope to be able to clean up the trackers before leaving for PyCon US (2024 – just in case ;))
yeah sorry I'm swamped right now, as you can tell in my own PR #1267 that hasn't moved in a while. I don't have the headspace for bigger changes right now, but it won't get lost as long as you leave it open. I hope to be able to clean up the trackers before leaving for PyCon US (2024 – just in case ;))
No problem at all! I'll leave it open and add some of the finishing touches (tests cases, docs) as I have time on the next week or two.
@hynek I've updated this to handle default factories and include a description of the functionality in the attrs by examples
section of the documentation.
Let me know when you have a chance to take a look.
Comparing RNKuhns:repr_optionally_exclude_param_defaults
(9f1963b) with main
(f5683b8)
❌ 3
regressions
✅ 5
untouched benchmarks
:warning: _Please fix the performance issues or acknowledge them on CodSpeed._
Benchmark | main |
RNKuhns:repr_optionally_exclude_param_defaults |
Change | |
---|---|---|---|---|
❌ | test_create_frozen_class |
1.7 s | 2.3 s | -25.32% |
❌ | test_create_simple_class |
1.5 s | 2.1 s | -28.06% |
❌ | test_create_simple_class_make_class |
1.5 s | 2 s | -28.49% |
Hey sorry once again, for all the delays. :( Before starting investigating, do you have any idea why this PR slows down class creation (not instantiation) by almost 30%? That's quite a lot and sadly a rather critical benchmark in the whole space of creating classes. :|
@hynek I do plan to circle back on this. I've just got a couple things going on at the moment.
Hey sorry once again, for all the delays. :( Before starting investigating, do you have any idea why this PR slows down class creation (not instantiation) by almost 30%? That's quite a lot and sadly a rather critical benchmark in the whole space of creating classes. :|
Not a problem -- I'll take a look at this and work through what is driving those performance degradations.
Summary
This PR provides functionality in line with #1193.
It adds a new parameter to attrs.define to allow users to toggle on/off the ability to create classes that dynamically generate their repr to include only parameters set to values other than their default. The added parameter is set to a default value that maintains the existing functionality (always have static repr).
The functionality is designed to work such as follows:
@hynek I'll look into creating some simple test cases (like above examples) to test cases for this. But I'd appreciate some feedback on whether this approach makes sense to you before I finish up with that.
Note there might be some nuisance edits to the
_make.py
thatruff
made when I saved the file in my setup, but these should be minor.Pull Request Check List
main
branch – use a separate branch!.pyi
).tests/typing_example.py
.attr/__init__.pyi
, they've also been re-imported inattrs/__init__.pyi
.docs/api.rst
by hand.@attr.s()
have to be added by hand too.versionadded
,versionchanged
, ordeprecated
directives. The next version is the second number in the current release + 1. The first number represents the current year. So if the current version on PyPI is 22.2.0, the next version is gonna be 22.3.0. If the next version is the first in the new year, it'll be 23.1.0..rst
and.md
files is written using semantic newlines.changelog.d
.