is_active: bool = user.is_logged_in and not user.is_banned
Type System & Annotations

Meaning

This chunk sets a boolean flag indicating whether a user is active by checking that they are logged in and not banned. It combines two boolean attributes with a logical AND and NOT to produce a clear activation condition. Developers reach for this pattern when they need to gate access to features based on user state.

Primary Function

Condition checking

Communicative Purpose

Ensures that only logged-in, unbanned users are considered active.

Pattern

flag: bool = account.is_logged_in and not account.is_banned

Core Structure

...: bool = ... .is_logged_in and not ... .is_banned

Função primária

Condition checking

Propósito comunicativo

Ensures that only logged-in, unbanned users are considered active.

Situações de gatilho

Web application: determining if a user should see personalized content; Authentication service: deciding whether to grant access to protected routes; Account management: enabling or disabling user-specific features based on status.

Contextos

Web backends, authentication systems, user management modules, SaaS platforms.

Padrão

flag: bool = account.is_logged_in and not account.is_banned

Estrutura central

...: bool = ... .is_logged_in and not ... .is_banned

Slots de substituição

flag: bool, account: object with boolean attributes is_logged_in and is_banned

Colocados típicos

  • if statements
  • feature flags
  • access control decorators
  • middleware checks.

Substituições comuns

  • user.is_logged_in && !user.is_banned (in languages without type annotations)
  • separate if checks (more verbose but clearer for complex logic).

Erros comuns

Using OR instead of AND (cause: misunderstanding logic; consequence: flag true for banned logged-in users), forgetting the NOT on is_banned (cause: oversight; consequence: flag true for banned users), omitting type annotation (cause: habit; consequence: less explicit contract).

Similar / contraste

user.is_logged_in alone (only checks login status, ignores bans), user.is_banned (only checks ban status, ignores login).

Interferências

Coming from JavaScript: may write `user.isLoggedIn && !user.isBanned` without type annotations — Python requires explicit bool type hint for clarity in modern codebases.

Família do chunk

  • user.is_logged_in
  • user.is_banned
  • access_control_check
  • feature_flag_evaluation

Nuance

Do not use when the login and ban checks need separate error handling or logging; performance impact is negligible as it's just two attribute lookups and boolean ops; boundary case: if user object is None, attribute access raises AttributeError — ensure user is validated before this line.

Efeito pragmático

Correctly encapsulates user activation logic in a single readable line, reducing duplication and making access control policies easier to audit.

Dica de memória

Think of a bouncer at a club: they only let you in if you're on the guest list (logged in) and not on the blacklist (not banned).

Frequência: Very highFormulaicidade: FixedPrioridade de aquisição: Automatic productionPrioridade de output: OutputTag de espaçamento: Immediate

Log in to save chunks.