[docs] flake8-self Private member access docs (#2912)

This commit is contained in:
Sawbez 2023-02-15 07:42:38 -08:00 committed by GitHub
parent cb971d3a48
commit 9168a12679
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View file

@ -9,6 +9,42 @@ use crate::registry::Diagnostic;
use crate::violation::Violation;
define_violation!(
/// ## What it does
/// Checks for accesses on "private" class members.
///
/// ## Why is this bad?
/// In Python, the convention is such that class members that are prefixed
/// with a single underscore, or prefixed but not suffixed with a double
/// underscore, are considered private and intended for internal use.
///
/// Using such "private" members is considered a misuse of the class, as
/// there are no guarantees that the member will be present in future
/// versions, that it will have the same type, or that it will have the same
/// behavior. Instead, use the class's public interface.
///
/// ## Example
/// ```python
/// class Class:
/// def __init__(self):
/// self._private_member = "..."
///
/// var = Class()
/// print(var._private_member)
/// ```
///
/// Use instead:
/// ```python
/// class Class:
/// def __init__(self):
/// self.public_member = "..."
///
/// var = Class()
/// print(var.public_member)
/// ```
///
/// ## References
/// * [_What is the meaning of single or double underscores before an object name?_](https://stackoverflow.com/questions/1301346/what-is-the-meaning-of-single-and-double-underscore-before-an-object-name)
/// ```
pub struct PrivateMemberAccess {
pub access: String,
}