Boolean prefix (ARCH2007)
Ce contenu n’est pas encore disponible dans votre langue.
Key python.naming.boolean-prefix · Severity info · Category naming
Boolean-typed members and accessors should carry an interrogative prefix such as is, has, can, or should. Without one, conditionals read poorly and intent becomes unclear.
Incorrect
Section titled “Incorrect”class Account: def __init__(self): self.active = True # boolean but no interrogative prefix self.admin = FalseCorrect
Section titled “Correct”class Account: def __init__(self): self.is_active = True self.is_admin = FalseAdd an is/has/can/should prefix to boolean members (e.g. active → is_active).