-
-
Notifications
You must be signed in to change notification settings - Fork 385
Disable __str__ by raising an exception #548
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
Comments
This strikes me as a feature better suited to an extension than something that belongs in |
Yeah, it seem very specialized to me. We could talk a out what makes it hard/impossible to implement something yourself? |
It's no problem to implement my own decorator; that's what I usually do. If FWIW, my view is that |
I don't disagree, but I think it depends on your use-case. I only get to see str in Exceptions (where we had to add explicit str support in attrs. :|) Well, creator-customization is coming…eventually. :) |
In Python,
repr
is used for helpful debugging output for the developer, andstr
is used for the end user. Becauseobject.__str__
defaults to behaving likeobject.__repr__
, the two representations can get somewhat mixed, sometimes by accident. Often this problem manifests by accidentally writing some object's repr into a file after callingstr()
on it. I'm increasingly feeling that these are two different representations, and they should not be used interchangeably. Instead, most objects should not have__str__
at all, and thatbuiltins.object.__str__
defaulting to behave like the repr is usually not what I want. To avoid this accidental mixing, I've taken to writing my own method:How would you feel about providing an option for this kind of method?
I'm filing this separately from #212 because it's a more specific idea for a particular implementation of
__str__
, rather than a framework for user-provided implementations.The text was updated successfully, but these errors were encountered: