Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease initialization of reprlib.Repr attributes #94343

Closed
finefoot opened this issue Jun 27, 2022 · 4 comments
Closed

Ease initialization of reprlib.Repr attributes #94343

finefoot opened this issue Jun 27, 2022 · 4 comments
Labels
type-feature A feature request or enhancement

Comments

@finefoot
Copy link
Contributor

If you want to use the reprlib.Repr class, currently, you need to instantiate an object and then set the desired attributes, afterwards, before you can actually use it:

from reprlib import Repr
myrepr = Repr()
myrepr.maxlevel = 10
myrepr.maxlist = 3
myrepr.maxdict = 1
myrepr.repr(myobject)

It might be more comfortable and clearer sometimes, to be able to set the attributes during the initialization:

from reprlib import Repr
myrepr = Repr(maxlevel=10, maxlist=3, maxdict=1)
myrepr.repr(myobject)

Furthermore, this would make it possible to use reprlib.Repr without having to designate a permanent name:

from reprlib import Repr
Repr(maxlevel=10, maxlist=3, maxdict=1).repr(myobject)
@finefoot finefoot added the type-feature A feature request or enhancement label Jun 27, 2022
@finefoot
Copy link
Contributor Author

My patch suggestion for Lib/reprlib.py looks like this:

38,51c38,55
<     def __init__(self):
<         self.fillvalue = '...'
<         self.maxlevel = 6
<         self.maxtuple = 6
<         self.maxlist = 6
<         self.maxarray = 5
<         self.maxdict = 4
<         self.maxset = 6
<         self.maxfrozenset = 6
<         self.maxdeque = 6
<         self.maxstring = 30
<         self.maxlong = 40
<         self.maxother = 30
---
>     def __init__(
>         self, fillvalue='...', maxlevel=6, maxtuple=6, maxlist=6, maxarray=5,
>         maxdict=4, maxset=6, maxfrozenset=6, maxdeque=6, maxstring=30,
>         maxlong=40, maxother=30,
>     ):
>         self.fillvalue = fillvalue
>         self.maxlevel = maxlevel
>         self.maxtuple = maxtuple
>         self.maxlist = maxlist
>         self.maxarray = maxarray
>         self.maxdict = maxdict
>         self.maxset = maxset
>         self.maxfrozenset = maxfrozenset
>         self.maxdeque = maxdeque
>         self.maxstring = maxstring
>         self.maxlong = maxlong
>         self.maxother = maxanother

However, it seems sensible to wait with the pull request if or until #92735 has been reviewed and (hopefully) merged.

@rhettinger
Copy link
Contributor

+1 This would be a nice improvement. Go ahead and submit a PR. There is no benefit to waiting on 92735 as it can easily be adapted.

@finefoot
Copy link
Contributor Author

finefoot commented Jul 7, 2022

Thanks for the encouragement :)

Go ahead and submit a PR

Done

@AlexWaygood
Copy link
Member

AlexWaygood commented Jul 7, 2022

Implemented in #94581. Thanks, @finefoot 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants