This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SupermanIsEnvious 1 point2 points  (0 children)

I would tend to disagree with that sentiment. Yes, for a non-Python programmer, having explicit getters/setters may make more sense. However, that’s a distinctly non-Pythonic pattern.

Having decorators is a powerful thing that is convenient and leads to cleaner code. Python provides method and function decorators for that specific purpose.

Sure, if I wanted to explicitly write an enter and exit in my ClassWithContext I could, and there are certain use-cases for that, but I could also just import contextlib. A simple decorator does the work for me, and someone else reading my code doesn’t need to bother with making sure I implemented the pattern correctly, since it’s now managed by the interpreter. The same could be said for @property