Detect getters and setters
See original GitHub issueRule request
Thesis
We can inspect class and instance methods to find these pattern: if class contains two methods like get_X
and set_X
we should raise UnpythonicGetterSetterViolation
We should also detect cases like:
- class has instance or class level attribute
x
or_x
or__x
- class has method called
get_x
orset_x
It is oop
violation.
Reasoning
Because python does not need this abstraction:
- Either use
@property
- Or just make the property public and change it
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Determine if a JavaScript property has a getter or setter defined?
I only want to define a getter/setter if there is not already one defined on the property. I need it to work in...
Read more >@Getter and @Setter - Project Lombok
A default getter simply returns the field, and is named getFoo if the field is called foo (or isFoo if the field's type...
Read more >Detect getters and setters stricter · Issue #1853 - GitHub
This code currently does not produce any violations: class SomeExample(object): my_value = 1 def get_value(self) -> int: return ...
Read more >Property getters and setters - The Modern JavaScript Tutorial
Accessor properties are represented by “getter” and “setter” methods. In an object literal they are denoted by get and set :.
Read more >getter - JavaScript - MDN Web Docs - Mozilla
Getters give you a way to define a property of an object, but they do not calculate the property's value until it is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes 👍
Sorry, that I am not able to express myself clear enough 🙂
This rule only checks method names. We need to detect patterns like
get_${existing_attribute_name}
andset_${existing_attribute_name}
and raise violations when any of these methods are found.Where
${existing_attribute_name}
can be public, protected, or private name of instance or class level attribute.