Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.requirement module

Provide an API that lets code express arbitrary requirements.

class betty.requirement.AllRequirements

  Bases: `RequirementCollection`

  A requirement that is met if all of the given requirements are met.

  __init__(*requirements: Requirement | None)
  async is_met() → bool

    Check if the requirement is met.

  async summary() → Localizable

    Get the requirement’s human-readable summary.

final class betty.requirement.AnyRequirement

  Bases: `RequirementCollection`

  A requirement that is met if any of the given requirements are met.

  __init__(*requirements: Requirement | None)
  async is_met() → bool

    Check if the requirement is met.

  async summary() → Localizable

    Get the requirement’s human-readable summary.

class betty.requirement.Requirement

  Bases: `Localizable`

  Express a requirement.

  async assert_met() → None

    Assert that the requirement is met.

  async details() → Localizable | None

    Get the requirement’s human-readable additional details.

  abstract async is_met() → bool

    Check if the requirement is met.

  localize(localizer: Localizer) → str

    Localize `self` to a human-readable string.

  reduce() → Requirement | None

    Remove unnecessary components of this requirement.

    - Collections can flatten unnecessary hierarchies.

    - Empty decorators or collections can ‘dissolve’ themselves and return None.

    This function MUST NOT modify self.

  abstract async summary() → Localizable

    Get the requirement’s human-readable summary.

class betty.requirement.RequirementCollection

  Bases: `Requirement`

  Provide a collection of zero or more requirements.

  __init__(*requirements: Requirement | None)
  localize(localizer: Localizer) → str

    Localize `self` to a human-readable string.

  reduce() → Requirement | None

    Remove unnecessary components of this requirement.

    - Collections can flatten unnecessary hierarchies.

    - Empty decorators or collections can ‘dissolve’ themselves and return None.

    This function MUST NOT modify self.

final exception betty.requirement.RequirementError

  Bases: `UserFacingError`, `RuntimeError`

  Raised when a requirement is not met.

  __init__(requirement: Requirement)
  requirement() → Requirement

    Get the requirement this error is for.