Skip to content

Should Ruff have an opinion on math.inf vs float("inf")? #15908

Open
@RubenVanEldik

Description

Description

Today I found out that there are two ways to define an infinity floating variable in Python:

  1. math.inf
  2. float("inf")

After quick testing it seems that they produce exactly the same object, but math.inf is 2-3 times faster. On top of that math.inf is shorter than float("inf"). Lastly, I think math.inf looks more pythonic than float("inf"), but that might be more personal.

Should we add a Ruff rule to prefer math.inf over float("inf") (and -math.inf over float("-inf"))

Keywords:

  • math.inf
  • float("inf")
  • infinity

Metadata

Assignees

No one assigned

    Labels

    needs-decisionAwaiting a decision from a maintainerruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions