[Python] What's the difference between Pint's "Quantity" and "PlainQuantity"?

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    My IDE (type-checking provided by the Pyright language server) doesn't like me passing pint.Quantity instances to functions type-hinted with pint.Quantity:

    from pint import Quantity

    def get_units(quantity: Quantity):
    return quantity.units

    get_unit(Quantity(value=1, units="m")) # IDE complains here


    My language server says this:

    Argument of type "PlainQuantity[Any]" cannot be assigned
    to parameter "quantity" of type "Quantity" in function
    "get_unit" [E]


    My questions are: what is PlainQuantity? Why does Quantity not return an instance of Quantity? Am I doing something wrong?

    Continue reading...

Compartilhe esta Página