prompt_id
int64
0
941
project
stringclasses
24 values
module
stringlengths
7
49
class
stringlengths
0
32
method
stringlengths
2
37
focal_method_txt
stringlengths
43
41.5k
focal_method_lines
listlengths
2
2
in_stack
bool
2 classes
globals
listlengths
0
16
type_context
stringlengths
79
41.9k
has_branch
bool
2 classes
total_branches
int64
0
3
345
pypara
pypara.monetary
Money
as_boolean
@abstractmethod def as_boolean(self) -> bool: """ Returns the logical representation of the money object. In particular: 1. ``False`` if money is *undefined* **or** money quantity is ``zero``. 2. ``True`` otherwise. """ raise NotImplementedError
[ 100, 109 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def as_boolean(self) -> bool: """ Returns the logical representation of the money object. In particular: 1. ``False`` if money is *undefined* **or** money quantity is ``zero``. 2. ``True`` otherwise. """ raise NotImplementedError
false
0
346
pypara
pypara.monetary
Money
as_float
@abstractmethod def as_float(self) -> float: """ Returns the quantity as a ``float`` if *defined*, raises class:`MonetaryOperationException` otherwise. """ raise NotImplementedError
[ 112, 116 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def as_float(self) -> float: """ Returns the quantity as a ``float`` if *defined*, raises class:`MonetaryOperationException` otherwise. """ raise NotImplementedError
false
0
347
pypara
pypara.monetary
Money
as_integer
@abstractmethod def as_integer(self) -> int: """ Returns the quantity as an ``int`` if *defined*, raises class:`MonetaryOperationException` otherwise. """ raise NotImplementedError
[ 119, 123 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def as_integer(self) -> int: """ Returns the quantity as an ``int`` if *defined*, raises class:`MonetaryOperationException` otherwise. """ raise NotImplementedError
false
0
348
pypara
pypara.monetary
Money
abs
@abstractmethod def abs(self) -> "Money": """ Returns the absolute money if *defined*, itself otherwise. """ raise NotImplementedError
[ 126, 130 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def abs(self) -> "Money": """ Returns the absolute money if *defined*, itself otherwise. """ raise NotImplementedError
false
0
349
pypara
pypara.monetary
Money
negative
@abstractmethod def negative(self) -> "Money": """ Negates the quantity of the monetary value if *defined*, itself otherwise. """ raise NotImplementedError
[ 133, 137 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def negative(self) -> "Money": """ Negates the quantity of the monetary value if *defined*, itself otherwise. """ raise NotImplementedError
false
0
350
pypara
pypara.monetary
Money
positive
@abstractmethod def positive(self) -> "Money": """ Returns same monetary value if *defined*, itself otherwise. """ raise NotImplementedError
[ 140, 144 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def positive(self) -> "Money": """ Returns same monetary value if *defined*, itself otherwise. """ raise NotImplementedError
false
0
351
pypara
pypara.monetary
Money
round
@abstractmethod def round(self, ndigits: int = 0) -> "Money": """ Rounds the quantity of the monetary value to ``ndigits`` by using ``HALF_EVEN`` method if *defined*, itself otherwise. """ raise NotImplementedError
[ 147, 152 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def round(self, ndigits: int = 0) -> "Money": """ Rounds the quantity of the monetary value to ``ndigits`` by using ``HALF_EVEN`` method if *defined*, itself otherwise. """ raise NotImplementedError
false
0
352
pypara
pypara.monetary
Money
add
@abstractmethod def add(self, other: "Money") -> "Money": """ Performs monetary addition on the money object and the given ``other`` money object. Note that:: 1. Raises :class:`IncompatibleCurrencyError` if currencies do not match. 2. If any of the operands are undefined, returns the other one conveniently. 3. Dates are carried forward as a result of addition of two defined money objects. """ raise NotImplementedError
[ 155, 165 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def add(self, other: "Money") -> "Money": """ Performs monetary addition on the money object and the given ``other`` money object. Note that:: 1. Raises :class:`IncompatibleCurrencyError` if currencies do not match. 2. If any of the operands are undefined, returns the other one conveniently. 3. Dates are carried forward as a result of addition of two defined money objects. """ raise NotImplementedError
false
0
353
pypara
pypara.monetary
Money
scalar_add
@abstractmethod def scalar_add(self, other: Numeric) -> "Money": """ Performs scalar addition on the quantity of the money. Note that undefined money object is returned as is. """ raise NotImplementedError
[ 168, 174 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def scalar_add(self, other: Numeric) -> "Money": """ Performs scalar addition on the quantity of the money. Note that undefined money object is returned as is. """ raise NotImplementedError
false
0
354
pypara
pypara.monetary
Money
subtract
@abstractmethod def subtract(self, other: "Money") -> "Money": """ Performs monetary subtraction on the money object and the given ``other`` money object. Note that:: 1. Raises :class:`IncompatibleCurrencyError` if currencies do not match. 2. If any of the operands are undefined, returns the other one conveniently. 3. Dates are carried forward as a result of addition of two defined money objects. """ raise NotImplementedError
[ 177, 187 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def subtract(self, other: "Money") -> "Money": """ Performs monetary subtraction on the money object and the given ``other`` money object. Note that:: 1. Raises :class:`IncompatibleCurrencyError` if currencies do not match. 2. If any of the operands are undefined, returns the other one conveniently. 3. Dates are carried forward as a result of addition of two defined money objects. """ raise NotImplementedError
false
0
355
pypara
pypara.monetary
Money
scalar_subtract
@abstractmethod def scalar_subtract(self, other: Numeric) -> "Money": """ Performs scalar subtraction on the quantity of the money. Note that undefined money object is returned as is. """ raise NotImplementedError
[ 190, 196 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def scalar_subtract(self, other: Numeric) -> "Money": """ Performs scalar subtraction on the quantity of the money. Note that undefined money object is returned as is. """ raise NotImplementedError
false
0
356
pypara
pypara.monetary
Money
multiply
@abstractmethod def multiply(self, other: Numeric) -> "Money": """ Performs scalar multiplication. Note that undefined money object is returned as is. """ raise NotImplementedError
[ 199, 205 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def multiply(self, other: Numeric) -> "Money": """ Performs scalar multiplication. Note that undefined money object is returned as is. """ raise NotImplementedError
false
0
357
pypara
pypara.monetary
Money
divide
@abstractmethod def divide(self, other: Numeric) -> "Money": """ Performs ordinary division on the money object if *defined*, itself otherwise. Note that division by zero yields an undefined money object. """ raise NotImplementedError
[ 208, 214 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def divide(self, other: Numeric) -> "Money": """ Performs ordinary division on the money object if *defined*, itself otherwise. Note that division by zero yields an undefined money object. """ raise NotImplementedError
false
0
358
pypara
pypara.monetary
Money
floor_divide
@abstractmethod def floor_divide(self, other: Numeric) -> "Money": """ Performs floor division on the money object if *defined*, itself otherwise. Note that division by zero yields an undefined money object. """ raise NotImplementedError
[ 217, 224 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def floor_divide(self, other: Numeric) -> "Money": """ Performs floor division on the money object if *defined*, itself otherwise. Note that division by zero yields an undefined money object. """ raise NotImplementedError
false
0
359
pypara
pypara.monetary
Money
lt
@abstractmethod def lt(self, other: "Money") -> bool: """ Applies "less than" comparison against ``other`` money. Note that:: 1. Undefined money objects are always less than ``other`` if ``other`` is not undefined, and 2. :class:`IncompatibleCurrencyError` is raised when comparing two defined money objects with different currencies. """ pass
[ 227, 237 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def lt(self, other: "Money") -> bool: """ Applies "less than" comparison against ``other`` money. Note that:: 1. Undefined money objects are always less than ``other`` if ``other`` is not undefined, and 2. :class:`IncompatibleCurrencyError` is raised when comparing two defined money objects with different currencies. """ pass
false
0
360
pypara
pypara.monetary
Money
lte
@abstractmethod def lte(self, other: "Money") -> bool: """ Applies "less than or equal to" comparison against ``other`` money. Note that:: 1. Undefined money objects are always less than or equal to ``other``, and 2. :class:`IncompatibleCurrencyError` is raised when comparing two defined money objects with different currencies. """ pass
[ 240, 250 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def lte(self, other: "Money") -> bool: """ Applies "less than or equal to" comparison against ``other`` money. Note that:: 1. Undefined money objects are always less than or equal to ``other``, and 2. :class:`IncompatibleCurrencyError` is raised when comparing two defined money objects with different currencies. """ pass
false
0
361
pypara
pypara.monetary
Money
gt
@abstractmethod def gt(self, other: "Money") -> bool: """ Applies "greater than" comparison against ``other`` money. Note that:: 1. Undefined money objects are never greater than ``other``, 2. Defined money objects are always greater than ``other`` if other is undefined, and 3. :class:`IncompatibleCurrencyError` is raised when comparing two defined money objects with different currencies. """ pass
[ 253, 264 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def gt(self, other: "Money") -> bool: """ Applies "greater than" comparison against ``other`` money. Note that:: 1. Undefined money objects are never greater than ``other``, 2. Defined money objects are always greater than ``other`` if other is undefined, and 3. :class:`IncompatibleCurrencyError` is raised when comparing two defined money objects with different currencies. """ pass
false
0
362
pypara
pypara.monetary
Money
gte
@abstractmethod def gte(self, other: "Money") -> bool: """ Applies "greater than or equal to" comparison against ``other`` money. Note that:: 1. Undefined money objects are never greater than or equal to ``other`` if ``other`` is defined, 2. Undefined money objects are greater than or equal to ``other`` if ``other is undefined, and 3. :class:`IncompatibleCurrencyError` is raised when comparing two defined money objects with different currencies. """ pass
[ 267, 278 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def gte(self, other: "Money") -> bool: """ Applies "greater than or equal to" comparison against ``other`` money. Note that:: 1. Undefined money objects are never greater than or equal to ``other`` if ``other`` is defined, 2. Undefined money objects are greater than or equal to ``other`` if ``other is undefined, and 3. :class:`IncompatibleCurrencyError` is raised when comparing two defined money objects with different currencies. """ pass
false
0
363
pypara
pypara.monetary
Money
with_ccy
@abstractmethod def with_ccy(self, ccy: Currency) -> "Money": """ Creates a new money object with the given currency if money is *defined*, returns itself otherwise. """ pass
[ 281, 285 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def with_ccy(self, ccy: Currency) -> "Money": """ Creates a new money object with the given currency if money is *defined*, returns itself otherwise. """ pass
false
0
364
pypara
pypara.monetary
Money
with_qty
@abstractmethod def with_qty(self, qty: Decimal) -> "Money": """ Creates a new money object with the given quantity if money is *defined*, returns itself otherwise. """ pass
[ 288, 292 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def with_qty(self, qty: Decimal) -> "Money": """ Creates a new money object with the given quantity if money is *defined*, returns itself otherwise. """ pass
false
0
365
pypara
pypara.monetary
Money
with_dov
@abstractmethod def with_dov(self, dov: Date) -> "Money": """ Creates a new money object with the given value date if money is *defined*, returns itself otherwise. """ pass
[ 295, 299 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def with_dov(self, dov: Date) -> "Money": """ Creates a new money object with the given value date if money is *defined*, returns itself otherwise. """ pass
false
0
366
pypara
pypara.monetary
Money
convert
@abstractmethod def convert(self, to: Currency, asof: Optional[Date] = None, strict: bool = False) -> "Money": """ Converts the monetary value from one currency to another. Raises :class:`FXRateLookupError` if no foreign exchange rate can be found for conversion. Note that we will carry the date forward as per ``asof`` date. """ raise NotImplementedError
[ 302, 310 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def convert(self, to: Currency, asof: Optional[Date] = None, strict: bool = False) -> "Money": """ Converts the monetary value from one currency to another. Raises :class:`FXRateLookupError` if no foreign exchange rate can be found for conversion. Note that we will carry the date forward as per ``asof`` date. """ raise NotImplementedError
false
0
367
pypara
pypara.monetary
Money
__bool__
@abstractmethod def __bool__(self) -> bool: pass
[ 330, 331 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __bool__(self) -> bool: pass
false
0
368
pypara
pypara.monetary
Money
__eq__
@abstractmethod def __eq__(self, other: Any) -> bool: pass
[ 334, 335 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __eq__(self, other: Any) -> bool: pass
false
0
369
pypara
pypara.monetary
Money
__abs__
@abstractmethod def __abs__(self) -> "Money": pass
[ 338, 339 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __abs__(self) -> "Money": pass
false
0
370
pypara
pypara.monetary
Money
__float__
@abstractmethod def __float__(self) -> float: pass
[ 342, 343 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __float__(self) -> float: pass
false
0
371
pypara
pypara.monetary
Money
__int__
@abstractmethod def __int__(self) -> int: pass
[ 346, 347 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __int__(self) -> int: pass
false
0
372
pypara
pypara.monetary
Money
__neg__
@abstractmethod def __neg__(self) -> "Money": pass
[ 365, 366 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __neg__(self) -> "Money": pass
false
0
373
pypara
pypara.monetary
Money
__pos__
@abstractmethod def __pos__(self) -> "Money": pass
[ 369, 370 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __pos__(self) -> "Money": pass
false
0
374
pypara
pypara.monetary
Money
__add__
@abstractmethod def __add__(self, other: "Money") -> "Money": pass
[ 373, 374 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __add__(self, other: "Money") -> "Money": pass
false
0
375
pypara
pypara.monetary
Money
__sub__
@abstractmethod def __sub__(self, other: "Money") -> "Money": pass
[ 377, 378 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __sub__(self, other: "Money") -> "Money": pass
false
0
376
pypara
pypara.monetary
Money
__mul__
@abstractmethod def __mul__(self, other: Numeric) -> "Money": pass
[ 381, 382 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __mul__(self, other: Numeric) -> "Money": pass
false
0
377
pypara
pypara.monetary
Money
__truediv__
@abstractmethod def __truediv__(self, other: Numeric) -> "Money": pass
[ 385, 386 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __truediv__(self, other: Numeric) -> "Money": pass
false
0
378
pypara
pypara.monetary
Money
__floordiv__
@abstractmethod def __floordiv__(self, other: Numeric) -> "Money": pass
[ 389, 390 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __floordiv__(self, other: Numeric) -> "Money": pass
false
0
379
pypara
pypara.monetary
Money
__lt__
@abstractmethod def __lt__(self, other: "Money") -> bool: pass
[ 393, 394 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __lt__(self, other: "Money") -> bool: pass
false
0
380
pypara
pypara.monetary
Money
__le__
@abstractmethod def __le__(self, other: "Money") -> bool: pass
[ 397, 398 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __le__(self, other: "Money") -> bool: pass
false
0
381
pypara
pypara.monetary
Money
__gt__
@abstractmethod def __gt__(self, other: "Money") -> bool: pass
[ 401, 402 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __gt__(self, other: "Money") -> bool: pass
false
0
382
pypara
pypara.monetary
Money
__ge__
@abstractmethod def __ge__(self, other: "Money") -> bool: pass
[ 405, 406 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Money: __slots__ = () NA: "Money" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __ge__(self, other: "Money") -> bool: pass
false
0
383
pypara
pypara.monetary
SomeMoney
round
def round(self, ndigits: int = 0) -> "Money": c, q, d = self dec = c.decimals return SomeMoney(c, q.__round__(ndigits if ndigits < dec else dec), d)
[ 444, 447 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class SomeMoney(Money, NamedTuple("SomeMoney", [("ccy", Currency), ("qty", Decimal), ("dov", Date)])): __slots__ = () defined = True undefined = False __bool__ = as_boolean __eq__ = is_equal __abs__ = abs __float__ = as_float __int__ = as_integer __neg__ = negative __pos__ = positive __add__ = add __sub__ = subtract __mul__ = multiply __truediv__ = divide __floordiv__ = floor_divide __lt__ = lt __le__ = lte __gt__ = gt __ge__ = gte def round(self, ndigits: int = 0) -> "Money": c, q, d = self dec = c.decimals return SomeMoney(c, q.__round__(ndigits if ndigits < dec else dec), d)
false
0
384
pypara
pypara.monetary
SomeMoney
with_dov
def with_dov(self, dov: Date) -> "Money": return SomeMoney(self[0], self[1], dov)
[ 551, 552 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class SomeMoney(Money, NamedTuple("SomeMoney", [("ccy", Currency), ("qty", Decimal), ("dov", Date)])): __slots__ = () defined = True undefined = False __bool__ = as_boolean __eq__ = is_equal __abs__ = abs __float__ = as_float __int__ = as_integer __neg__ = negative __pos__ = positive __add__ = add __sub__ = subtract __mul__ = multiply __truediv__ = divide __floordiv__ = floor_divide __lt__ = lt __le__ = lte __gt__ = gt __ge__ = gte def with_dov(self, dov: Date) -> "Money": return SomeMoney(self[0], self[1], dov)
false
0
385
pypara
pypara.monetary
SomeMoney
convert
def convert(self, to: Currency, asof: Optional[Date] = None, strict: bool = False) -> "Money": ## Get slots: ccy, qty, dov = self ## Get date of conversion: asof = asof or dov ## Attempt to get the FX rate: try: rate = FXRateService.default.query(ccy, to, asof, strict) # type: ignore except AttributeError as exc: if FXRateService.default is None: raise ProgrammingError("Did you implement and set the default FX rate service?") else: raise exc ## Do we have a rate? if rate is None: ## Nope, shall we raise exception? if strict: ## Yep: raise FXRateLookupError(ccy, to, asof) else: ## Just return NA: return NoMoney ## Compute and return: return SomeMoney(to, (qty * rate.value).quantize(to.quantizer), asof)
[ 554, 581 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class SomeMoney(Money, NamedTuple("SomeMoney", [("ccy", Currency), ("qty", Decimal), ("dov", Date)])): __slots__ = () defined = True undefined = False __bool__ = as_boolean __eq__ = is_equal __abs__ = abs __float__ = as_float __int__ = as_integer __neg__ = negative __pos__ = positive __add__ = add __sub__ = subtract __mul__ = multiply __truediv__ = divide __floordiv__ = floor_divide __lt__ = lt __le__ = lte __gt__ = gt __ge__ = gte def convert(self, to: Currency, asof: Optional[Date] = None, strict: bool = False) -> "Money": ## Get slots: ccy, qty, dov = self ## Get date of conversion: asof = asof or dov ## Attempt to get the FX rate: try: rate = FXRateService.default.query(ccy, to, asof, strict) # type: ignore except AttributeError as exc: if FXRateService.default is None: raise ProgrammingError("Did you implement and set the default FX rate service?") else: raise exc ## Do we have a rate? if rate is None: ## Nope, shall we raise exception? if strict: ## Yep: raise FXRateLookupError(ccy, to, asof) else: ## Just return NA: return NoMoney ## Compute and return: return SomeMoney(to, (qty * rate.value).quantize(to.quantizer), asof)
true
2
386
pypara
pypara.monetary
Price
is_equal
@abstractmethod def is_equal(self, other: Any) -> bool: """ Checks the equality of two price objects. In particular: 1. ``True`` if ``other`` is a price object **and** all slots are same. 2. ``False`` otherwise. """ raise NotImplementedError
[ 771, 780 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def is_equal(self, other: Any) -> bool: """ Checks the equality of two price objects. In particular: 1. ``True`` if ``other`` is a price object **and** all slots are same. 2. ``False`` otherwise. """ raise NotImplementedError
false
0
387
pypara
pypara.monetary
Price
as_boolean
@abstractmethod def as_boolean(self) -> bool: """ Returns the logical representation of the price object. In particular: 1. ``False`` if price is *undefined* **or** price quantity is ``zero``. 2. ``True`` otherwise. """ raise NotImplementedError
[ 783, 792 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def as_boolean(self) -> bool: """ Returns the logical representation of the price object. In particular: 1. ``False`` if price is *undefined* **or** price quantity is ``zero``. 2. ``True`` otherwise. """ raise NotImplementedError
false
0
388
pypara
pypara.monetary
Price
as_float
@abstractmethod def as_float(self) -> float: """ Returns the quantity as a ``float`` if *defined*, raises class:`MonetaryOperationException` otherwise. """ raise NotImplementedError
[ 795, 799 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def as_float(self) -> float: """ Returns the quantity as a ``float`` if *defined*, raises class:`MonetaryOperationException` otherwise. """ raise NotImplementedError
false
0
389
pypara
pypara.monetary
Price
as_integer
@abstractmethod def as_integer(self) -> int: """ Returns the quantity as an ``int`` if *defined*, raises class:`MonetaryOperationException` otherwise. """ raise NotImplementedError
[ 802, 806 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def as_integer(self) -> int: """ Returns the quantity as an ``int`` if *defined*, raises class:`MonetaryOperationException` otherwise. """ raise NotImplementedError
false
0
390
pypara
pypara.monetary
Price
abs
@abstractmethod def abs(self) -> "Price": """ Returns the absolute price if *defined*, itself otherwise. """ raise NotImplementedError
[ 809, 813 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def abs(self) -> "Price": """ Returns the absolute price if *defined*, itself otherwise. """ raise NotImplementedError
false
0
391
pypara
pypara.monetary
Price
negative
@abstractmethod def negative(self) -> "Price": """ Negates the quantity of the monetary value if *defined*, itself otherwise. """ raise NotImplementedError
[ 816, 820 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def negative(self) -> "Price": """ Negates the quantity of the monetary value if *defined*, itself otherwise. """ raise NotImplementedError
false
0
392
pypara
pypara.monetary
Price
positive
@abstractmethod def positive(self) -> "Price": """ Returns same monetary value if *defined*, itself otherwise. """ raise NotImplementedError
[ 823, 827 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def positive(self) -> "Price": """ Returns same monetary value if *defined*, itself otherwise. """ raise NotImplementedError
false
0
393
pypara
pypara.monetary
Price
round
@abstractmethod def round(self, ndigits: int = 0) -> "Price": """ Rounds the quantity of the monetary value to ``ndigits`` by using ``HALF_EVEN`` method if *defined*, itself otherwise. """ raise NotImplementedError
[ 830, 835 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def round(self, ndigits: int = 0) -> "Price": """ Rounds the quantity of the monetary value to ``ndigits`` by using ``HALF_EVEN`` method if *defined*, itself otherwise. """ raise NotImplementedError
false
0
394
pypara
pypara.monetary
Price
add
@abstractmethod def add(self, other: "Price") -> "Price": """ Performs monetary addition on the price object and the given ``other`` price object. Note that:: 1. Raises :class:`IncompatibleCurrencyError` if currencies do not match. 2. If any of the operands are undefined, returns the other one conveniently. 3. Dates are carried forward as a result of addition of two defined price objects. """ raise NotImplementedError
[ 838, 848 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def add(self, other: "Price") -> "Price": """ Performs monetary addition on the price object and the given ``other`` price object. Note that:: 1. Raises :class:`IncompatibleCurrencyError` if currencies do not match. 2. If any of the operands are undefined, returns the other one conveniently. 3. Dates are carried forward as a result of addition of two defined price objects. """ raise NotImplementedError
false
0
395
pypara
pypara.monetary
Price
scalar_add
@abstractmethod def scalar_add(self, other: Numeric) -> "Price": """ Performs scalar addition on the quantity of the price. Note that undefined price object is returned as is. """ raise NotImplementedError
[ 851, 857 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def scalar_add(self, other: Numeric) -> "Price": """ Performs scalar addition on the quantity of the price. Note that undefined price object is returned as is. """ raise NotImplementedError
false
0
396
pypara
pypara.monetary
Price
subtract
@abstractmethod def subtract(self, other: "Price") -> "Price": """ Performs monetary subtraction on the price object and the given ``other`` price object. Note that:: 1. Raises :class:`IncompatibleCurrencyError` if currencies do not match. 2. If any of the operands are undefined, returns the other one conveniently. 3. Dates are carried forward as a result of addition of two defined price objects. """ raise NotImplementedError
[ 860, 870 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def subtract(self, other: "Price") -> "Price": """ Performs monetary subtraction on the price object and the given ``other`` price object. Note that:: 1. Raises :class:`IncompatibleCurrencyError` if currencies do not match. 2. If any of the operands are undefined, returns the other one conveniently. 3. Dates are carried forward as a result of addition of two defined price objects. """ raise NotImplementedError
false
0
397
pypara
pypara.monetary
Price
scalar_subtract
@abstractmethod def scalar_subtract(self, other: Numeric) -> "Price": """ Performs scalar subtraction on the quantity of the price. Note that undefined price object is returned as is. """ raise NotImplementedError
[ 873, 879 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def scalar_subtract(self, other: Numeric) -> "Price": """ Performs scalar subtraction on the quantity of the price. Note that undefined price object is returned as is. """ raise NotImplementedError
false
0
398
pypara
pypara.monetary
Price
multiply
@abstractmethod def multiply(self, other: Numeric) -> "Price": """ Performs scalar multiplication. Note that undefined price object is returned as is. """ raise NotImplementedError
[ 882, 888 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def multiply(self, other: Numeric) -> "Price": """ Performs scalar multiplication. Note that undefined price object is returned as is. """ raise NotImplementedError
false
0
399
pypara
pypara.monetary
Price
times
@abstractmethod def times(self, other: Numeric) -> "Money": """ Performs monetary multiplication operation. Note that undefined price object is returned as is. """ raise NotImplementedError
[ 891, 897 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def times(self, other: Numeric) -> "Money": """ Performs monetary multiplication operation. Note that undefined price object is returned as is. """ raise NotImplementedError
false
0
400
pypara
pypara.monetary
Price
divide
@abstractmethod def divide(self, other: Numeric) -> "Price": """ Performs ordinary division on the price object if *defined*, itself otherwise. Note that division by zero yields an undefined price object. """ raise NotImplementedError
[ 900, 906 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def divide(self, other: Numeric) -> "Price": """ Performs ordinary division on the price object if *defined*, itself otherwise. Note that division by zero yields an undefined price object. """ raise NotImplementedError
false
0
401
pypara
pypara.monetary
Price
floor_divide
@abstractmethod def floor_divide(self, other: Numeric) -> "Price": """ Performs floor division on the price object if *defined*, itself otherwise. Note that division by zero yields an undefined price object. """ raise NotImplementedError
[ 909, 916 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def floor_divide(self, other: Numeric) -> "Price": """ Performs floor division on the price object if *defined*, itself otherwise. Note that division by zero yields an undefined price object. """ raise NotImplementedError
false
0
402
pypara
pypara.monetary
Price
lt
@abstractmethod def lt(self, other: "Price") -> bool: """ Applies "less than" comparison against ``other`` price. Note that:: 1. Undefined price objects are always less than ``other`` if ``other`` is not undefined, and 2. :class:`IncompatibleCurrencyError` is raised when comparing two defined price objects with different currencies. """ pass
[ 919, 929 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def lt(self, other: "Price") -> bool: """ Applies "less than" comparison against ``other`` price. Note that:: 1. Undefined price objects are always less than ``other`` if ``other`` is not undefined, and 2. :class:`IncompatibleCurrencyError` is raised when comparing two defined price objects with different currencies. """ pass
false
0
403
pypara
pypara.monetary
Price
lte
@abstractmethod def lte(self, other: "Price") -> bool: """ Applies "less than or equal to" comparison against ``other`` price. Note that:: 1. Undefined price objects are always less than or equal to ``other``, and 2. :class:`IncompatibleCurrencyError` is raised when comparing two defined price objects with different currencies. """ pass
[ 932, 942 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def lte(self, other: "Price") -> bool: """ Applies "less than or equal to" comparison against ``other`` price. Note that:: 1. Undefined price objects are always less than or equal to ``other``, and 2. :class:`IncompatibleCurrencyError` is raised when comparing two defined price objects with different currencies. """ pass
false
0
404
pypara
pypara.monetary
Price
gt
@abstractmethod def gt(self, other: "Price") -> bool: """ Applies "greater than" comparison against ``other`` price. Note that:: 1. Undefined price objects are never greater than ``other``, 2. Defined price objects are always greater than ``other`` if other is undefined, and 3. :class:`IncompatibleCurrencyError` is raised when comparing two defined price objects with different currencies. """ pass
[ 945, 956 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def gt(self, other: "Price") -> bool: """ Applies "greater than" comparison against ``other`` price. Note that:: 1. Undefined price objects are never greater than ``other``, 2. Defined price objects are always greater than ``other`` if other is undefined, and 3. :class:`IncompatibleCurrencyError` is raised when comparing two defined price objects with different currencies. """ pass
false
0
405
pypara
pypara.monetary
Price
gte
@abstractmethod def gte(self, other: "Price") -> bool: """ Applies "greater than or equal to" comparison against ``other`` price. Note that:: 1. Undefined price objects are never greater than or equal to ``other`` if ``other`` is defined, 2. Undefined price objects are greater than or equal to ``other`` if ``other is undefined, and 3. :class:`IncompatibleCurrencyError` is raised when comparing two defined price objects with different currencies. """ pass
[ 959, 970 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class IncompatibleCurrencyError(ValueError): def __init__(self, ccy1: Currency, ccy2: Currency, operation: str = "<Unspecified>") -> None: """ Initializes an incompatible currency error message. """ ## Keep sloys: self.ccy1 = ccy1 self.ccy2 = ccy2 self.operation = operation ## Call super: super().__init__(f"{ccy1.code} vs {ccy2.code} are incompatible for operation '{operation}'.") class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def gte(self, other: "Price") -> bool: """ Applies "greater than or equal to" comparison against ``other`` price. Note that:: 1. Undefined price objects are never greater than or equal to ``other`` if ``other`` is defined, 2. Undefined price objects are greater than or equal to ``other`` if ``other is undefined, and 3. :class:`IncompatibleCurrencyError` is raised when comparing two defined price objects with different currencies. """ pass
false
0
406
pypara
pypara.monetary
Price
with_ccy
@abstractmethod def with_ccy(self, ccy: Currency) -> "Price": """ Creates a new price object with the given currency if price is *defined*, returns itself otherwise. """ pass
[ 973, 977 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def with_ccy(self, ccy: Currency) -> "Price": """ Creates a new price object with the given currency if price is *defined*, returns itself otherwise. """ pass
false
0
407
pypara
pypara.monetary
Price
with_qty
@abstractmethod def with_qty(self, qty: Decimal) -> "Price": """ Creates a new price object with the given quantity if price is *defined*, returns itself otherwise. """ pass
[ 980, 984 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def with_qty(self, qty: Decimal) -> "Price": """ Creates a new price object with the given quantity if price is *defined*, returns itself otherwise. """ pass
false
0
408
pypara
pypara.monetary
Price
with_dov
@abstractmethod def with_dov(self, dov: Date) -> "Price": """ Creates a new price object with the given value date if price is *defined*, returns itself otherwise. """ pass
[ 987, 991 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def with_dov(self, dov: Date) -> "Price": """ Creates a new price object with the given value date if price is *defined*, returns itself otherwise. """ pass
false
0
409
pypara
pypara.monetary
Price
convert
@abstractmethod def convert(self, to: Currency, asof: Optional[Date] = None, strict: bool = False) -> "Price": """ Converts the monetary value from one currency to another. Raises :class:`FXRateLookupError` if no foreign exchange rate can be found for conversion. Note that we will carry the date forward as per ``asof`` date. """ raise NotImplementedError
[ 994, 1002 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def convert(self, to: Currency, asof: Optional[Date] = None, strict: bool = False) -> "Price": """ Converts the monetary value from one currency to another. Raises :class:`FXRateLookupError` if no foreign exchange rate can be found for conversion. Note that we will carry the date forward as per ``asof`` date. """ raise NotImplementedError
false
0
410
pypara
pypara.monetary
Price
__bool__
@abstractmethod def __bool__(self) -> bool: pass
[ 1022, 1023 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __bool__(self) -> bool: pass
false
0
411
pypara
pypara.monetary
Price
__eq__
@abstractmethod def __eq__(self, other: Any) -> bool: pass
[ 1026, 1027 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __eq__(self, other: Any) -> bool: pass
false
0
412
pypara
pypara.monetary
Price
__abs__
@abstractmethod def __abs__(self) -> "Price": pass
[ 1030, 1031 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __abs__(self) -> "Price": pass
false
0
413
pypara
pypara.monetary
Price
__float__
@abstractmethod def __float__(self) -> float: pass
[ 1034, 1035 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __float__(self) -> float: pass
false
0
414
pypara
pypara.monetary
Price
__int__
@abstractmethod def __int__(self) -> int: pass
[ 1038, 1039 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __int__(self) -> int: pass
false
0
415
pypara
pypara.monetary
Price
__neg__
@abstractmethod def __neg__(self) -> "Price": pass
[ 1057, 1058 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __neg__(self) -> "Price": pass
false
0
416
pypara
pypara.monetary
Price
__pos__
@abstractmethod def __pos__(self) -> "Price": pass
[ 1061, 1062 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __pos__(self) -> "Price": pass
false
0
417
pypara
pypara.monetary
Price
__add__
@abstractmethod def __add__(self, other: "Price") -> "Price": pass
[ 1065, 1066 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __add__(self, other: "Price") -> "Price": pass
false
0
418
pypara
pypara.monetary
Price
__sub__
@abstractmethod def __sub__(self, other: "Price") -> "Price": pass
[ 1069, 1070 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __sub__(self, other: "Price") -> "Price": pass
false
0
419
pypara
pypara.monetary
Price
__mul__
@abstractmethod def __mul__(self, other: Numeric) -> "Price": pass
[ 1073, 1074 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __mul__(self, other: Numeric) -> "Price": pass
false
0
420
pypara
pypara.monetary
Price
__truediv__
@abstractmethod def __truediv__(self, other: Numeric) -> "Price": pass
[ 1077, 1078 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __truediv__(self, other: Numeric) -> "Price": pass
false
0
421
pypara
pypara.monetary
Price
__floordiv__
@abstractmethod def __floordiv__(self, other: Numeric) -> "Price": pass
[ 1081, 1082 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __floordiv__(self, other: Numeric) -> "Price": pass
false
0
422
pypara
pypara.monetary
Price
__lt__
@abstractmethod def __lt__(self, other: "Price") -> bool: pass
[ 1085, 1086 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __lt__(self, other: "Price") -> bool: pass
false
0
423
pypara
pypara.monetary
Price
__le__
@abstractmethod def __le__(self, other: "Price") -> bool: pass
[ 1089, 1090 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __le__(self, other: "Price") -> bool: pass
false
0
424
pypara
pypara.monetary
Price
__gt__
@abstractmethod def __gt__(self, other: "Price") -> bool: pass
[ 1093, 1094 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __gt__(self, other: "Price") -> bool: pass
false
0
425
pypara
pypara.monetary
Price
__ge__
@abstractmethod def __ge__(self, other: "Price") -> bool: pass
[ 1097, 1098 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class Price: __slots__ = () NA: "Price" ccy: Currency qty: Decimal dov: Date defined: bool undefined: bool @abstractmethod def __ge__(self, other: "Price") -> bool: pass
false
0
426
pypara
pypara.monetary
SomePrice
with_dov
def with_dov(self, dov: Date) -> "Price": return SomePrice(self[0], self[1], dov)
[ 1245, 1246 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class SomePrice(Price, NamedTuple("SomePrice", [("ccy", Currency), ("qty", Decimal), ("dov", Date)])): __slots__ = () defined = True undefined = False __bool__ = as_boolean __eq__ = is_equal __abs__ = abs __float__ = as_float __int__ = as_integer __neg__ = negative __pos__ = positive __add__ = add __sub__ = subtract __mul__ = multiply __truediv__ = divide __floordiv__ = floor_divide __lt__ = lt __le__ = lte __gt__ = gt __ge__ = gte def with_dov(self, dov: Date) -> "Price": return SomePrice(self[0], self[1], dov)
false
0
427
pypara
pypara.monetary
SomePrice
convert
def convert(self, to: Currency, asof: Optional[Date] = None, strict: bool = False) -> "Price": ## Get slots: ccy, qty, dov = self ## Get date of conversion: asof = asof or dov ## Attempt to get the FX rate: try: rate = FXRateService.default.query(ccy, to, asof, strict) # type: ignore except AttributeError as exc: if FXRateService.default is None: raise ProgrammingError("Did you implement and set the default FX rate service?") else: raise exc ## Do we have a rate? if rate is None: ## Nope, shall we raise exception? if strict: ## Yep: raise FXRateLookupError(ccy, to, asof) else: ## Just return NA: return NoPrice ## Compute and return: return SomePrice(to, qty * rate.value, asof)
[ 1248, 1275 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class SomePrice(Price, NamedTuple("SomePrice", [("ccy", Currency), ("qty", Decimal), ("dov", Date)])): __slots__ = () defined = True undefined = False __bool__ = as_boolean __eq__ = is_equal __abs__ = abs __float__ = as_float __int__ = as_integer __neg__ = negative __pos__ = positive __add__ = add __sub__ = subtract __mul__ = multiply __truediv__ = divide __floordiv__ = floor_divide __lt__ = lt __le__ = lte __gt__ = gt __ge__ = gte def convert(self, to: Currency, asof: Optional[Date] = None, strict: bool = False) -> "Price": ## Get slots: ccy, qty, dov = self ## Get date of conversion: asof = asof or dov ## Attempt to get the FX rate: try: rate = FXRateService.default.query(ccy, to, asof, strict) # type: ignore except AttributeError as exc: if FXRateService.default is None: raise ProgrammingError("Did you implement and set the default FX rate service?") else: raise exc ## Do we have a rate? if rate is None: ## Nope, shall we raise exception? if strict: ## Yep: raise FXRateLookupError(ccy, to, asof) else: ## Just return NA: return NoPrice ## Compute and return: return SomePrice(to, qty * rate.value, asof)
true
2
428
pypara
pypara.monetary
NonePrice
with_dov
def with_dov(self, dov: Date) -> "Price": return self
[ 1389, 1390 ]
false
[ "__all__", "Money", "NA", "Price" ]
from abc import abstractmethod from decimal import Decimal, DivisionByZero, InvalidOperation from typing import Any, NamedTuple, Optional, Union, overload from .commons.errors import ProgrammingError from .commons.numbers import Numeric from .commons.zeitgeist import Date from .currencies import Currency from .exchange import FXRateLookupError, FXRateService __all__ = [ "IncompatibleCurrencyError", "MonetaryOperationException", "Money", "NoMoney", "NoPrice", "NoneMoney", "NonePrice", "Price", "SomeMoney", "SomePrice", ] Money.NA = NoMoney = NoneMoney() Price.NA = NoPrice = NonePrice() Price.NA = NoPrice = NonePrice() class NonePrice(Price): __slots__ = () defined = False undefined = True money = NoMoney __bool__ = as_boolean __eq__ = is_equal __abs__ = abs __float__ = as_float __int__ = as_integer __neg__ = negative __pos__ = positive __add__ = add __sub__ = subtract __mul__ = multiply __truediv__ = divide __floordiv__ = floor_divide __lt__ = lt __le__ = lte __gt__ = gt __ge__ = gte def with_dov(self, dov: Date) -> "Price": return self
false
0
429
pysnooper
pysnooper.pycompat
timedelta_format
def timedelta_format(timedelta): time = (datetime_module.datetime.min + timedelta).time() return time_isoformat(time, timespec='microseconds')
[ 85, 87 ]
false
[ "PY3", "PY2" ]
import abc import os import inspect import sys import datetime as datetime_module PY3 = (sys.version_info[0] == 3) PY2 = not PY3 def timedelta_format(timedelta): time = (datetime_module.datetime.min + timedelta).time() return time_isoformat(time, timespec='microseconds')
false
0
430
pysnooper
pysnooper.pycompat
timedelta_parse
def timedelta_parse(s): hours, minutes, seconds, microseconds = map( int, s.replace('.', ':').split(':') ) return datetime_module.timedelta(hours=hours, minutes=minutes, seconds=seconds, microseconds=microseconds)
[ 89, 94 ]
false
[ "PY3", "PY2" ]
import abc import os import inspect import sys import datetime as datetime_module PY3 = (sys.version_info[0] == 3) PY2 = not PY3 def timedelta_parse(s): hours, minutes, seconds, microseconds = map( int, s.replace('.', ':').split(':') ) return datetime_module.timedelta(hours=hours, minutes=minutes, seconds=seconds, microseconds=microseconds)
false
0
431
pysnooper
pysnooper.tracer
get_local_reprs
def get_local_reprs(frame, watch=(), custom_repr=(), max_length=None, normalize=False): code = frame.f_code vars_order = (code.co_varnames + code.co_cellvars + code.co_freevars + tuple(frame.f_locals.keys())) result_items = [(key, utils.get_shortish_repr(value, custom_repr, max_length, normalize)) for key, value in frame.f_locals.items()] result_items.sort(key=lambda key_value: vars_order.index(key_value[0])) result = collections.OrderedDict(result_items) for variable in watch: result.update(sorted(variable.items(frame, normalize))) return result
[ 24, 37 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) def get_local_reprs(frame, watch=(), custom_repr=(), max_length=None, normalize=False): code = frame.f_code vars_order = (code.co_varnames + code.co_cellvars + code.co_freevars + tuple(frame.f_locals.keys())) result_items = [(key, utils.get_shortish_repr(value, custom_repr, max_length, normalize)) for key, value in frame.f_locals.items()] result_items.sort(key=lambda key_value: vars_order.index(key_value[0])) result = collections.OrderedDict(result_items) for variable in watch: result.update(sorted(variable.items(frame, normalize))) return result
true
2
432
pysnooper
pysnooper.tracer
get_path_and_source_from_frame
def get_path_and_source_from_frame(frame): globs = frame.f_globals or {} module_name = globs.get('__name__') file_name = frame.f_code.co_filename cache_key = (module_name, file_name) try: return source_and_path_cache[cache_key] except KeyError: pass loader = globs.get('__loader__') source = None if hasattr(loader, 'get_source'): try: source = loader.get_source(module_name) except ImportError: pass if source is not None: source = source.splitlines() if source is None: ipython_filename_match = ipython_filename_pattern.match(file_name) if ipython_filename_match: entry_number = int(ipython_filename_match.group(1)) try: import IPython ipython_shell = IPython.get_ipython() ((_, _, source_chunk),) = ipython_shell.history_manager. \ get_range(0, entry_number, entry_number + 1) source = source_chunk.splitlines() except Exception: pass else: try: with open(file_name, 'rb') as fp: source = fp.read().splitlines() except utils.file_reading_errors: pass if not source: # We used to check `if source is None` but I found a rare bug where it # was empty, but not `None`, so now we check `if not source`. source = UnavailableSource() # If we just read the source from a file, or if the loader did not # apply tokenize.detect_encoding to decode the source into a # string, then we should do that ourselves. if isinstance(source[0], bytes): encoding = 'utf-8' for line in source[:2]: # File coding may be specified. Match pattern from PEP-263 # (https://www.python.org/dev/peps/pep-0263/) match = re.search(br'coding[:=]\s*([-\w.]+)', line) if match: encoding = match.group(1).decode('ascii') break source = [pycompat.text_type(sline, encoding, 'replace') for sline in source] result = (file_name, source) source_and_path_cache[cache_key] = result return result
[ 48, 107 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) def get_path_and_source_from_frame(frame): globs = frame.f_globals or {} module_name = globs.get('__name__') file_name = frame.f_code.co_filename cache_key = (module_name, file_name) try: return source_and_path_cache[cache_key] except KeyError: pass loader = globs.get('__loader__') source = None if hasattr(loader, 'get_source'): try: source = loader.get_source(module_name) except ImportError: pass if source is not None: source = source.splitlines() if source is None: ipython_filename_match = ipython_filename_pattern.match(file_name) if ipython_filename_match: entry_number = int(ipython_filename_match.group(1)) try: import IPython ipython_shell = IPython.get_ipython() ((_, _, source_chunk),) = ipython_shell.history_manager. \ get_range(0, entry_number, entry_number + 1) source = source_chunk.splitlines() except Exception: pass else: try: with open(file_name, 'rb') as fp: source = fp.read().splitlines() except utils.file_reading_errors: pass if not source: # We used to check `if source is None` but I found a rare bug where it # was empty, but not `None`, so now we check `if not source`. source = UnavailableSource() # If we just read the source from a file, or if the loader did not # apply tokenize.detect_encoding to decode the source into a # string, then we should do that ourselves. if isinstance(source[0], bytes): encoding = 'utf-8' for line in source[:2]: # File coding may be specified. Match pattern from PEP-263 # (https://www.python.org/dev/peps/pep-0263/) match = re.search(br'coding[:=]\s*([-\w.]+)', line) if match: encoding = match.group(1).decode('ascii') break source = [pycompat.text_type(sline, encoding, 'replace') for sline in source] result = (file_name, source) source_and_path_cache[cache_key] = result return result
true
2
433
pysnooper
pysnooper.tracer
get_write_function
def get_write_function(output, overwrite): is_path = isinstance(output, (pycompat.PathLike, str)) if overwrite and not is_path: raise Exception('`overwrite=True` can only be used when writing ' 'content to file.') if output is None: def write(s): stderr = sys.stderr try: stderr.write(s) except UnicodeEncodeError: # God damn Python 2 stderr.write(utils.shitcode(s)) elif is_path: return FileWriter(output, overwrite).write elif callable(output): write = output else: assert isinstance(output, utils.WritableStream) def write(s): output.write(s) return write
[ 110, 132 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) class FileWriter(object): def __init__(self, path, overwrite): self.path = pycompat.text_type(path) self.overwrite = overwrite def get_write_function(output, overwrite): is_path = isinstance(output, (pycompat.PathLike, str)) if overwrite and not is_path: raise Exception('`overwrite=True` can only be used when writing ' 'content to file.') if output is None: def write(s): stderr = sys.stderr try: stderr.write(s) except UnicodeEncodeError: # God damn Python 2 stderr.write(utils.shitcode(s)) elif is_path: return FileWriter(output, overwrite).write elif callable(output): write = output else: assert isinstance(output, utils.WritableStream) def write(s): output.write(s) return write
true
2
434
pysnooper
pysnooper.tracer
FileWriter
write
def write(self, s): with open(self.path, 'w' if self.overwrite else 'a', encoding='utf-8') as output_file: output_file.write(s) self.overwrite = False
[ 140, 144 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) class FileWriter(object): def __init__(self, path, overwrite): self.path = pycompat.text_type(path) self.overwrite = overwrite def write(self, s): with open(self.path, 'w' if self.overwrite else 'a', encoding='utf-8') as output_file: output_file.write(s) self.overwrite = False
false
0
435
pysnooper
pysnooper.tracer
Tracer
__init__
def __init__(self, output=None, watch=(), watch_explode=(), depth=1, prefix='', overwrite=False, thread_info=False, custom_repr=(), max_variable_length=100, normalize=False, relative_time=False): self._write = get_write_function(output, overwrite) self.watch = [ v if isinstance(v, BaseVariable) else CommonVariable(v) for v in utils.ensure_tuple(watch) ] + [ v if isinstance(v, BaseVariable) else Exploding(v) for v in utils.ensure_tuple(watch_explode) ] self.frame_to_local_reprs = {} self.start_times = {} self.depth = depth self.prefix = prefix self.thread_info = thread_info self.thread_info_padding = 0 assert self.depth >= 1 self.target_codes = set() self.target_frames = set() self.thread_local = threading.local() if len(custom_repr) == 2 and not all(isinstance(x, pycompat.collections_abc.Iterable) for x in custom_repr): custom_repr = (custom_repr,) self.custom_repr = custom_repr self.last_source_path = None self.max_variable_length = max_variable_length self.normalize = normalize self.relative_time = relative_time
[ 205, 234 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) class Tracer: def __init__(self, output=None, watch=(), watch_explode=(), depth=1, prefix='', overwrite=False, thread_info=False, custom_repr=(), max_variable_length=100, normalize=False, relative_time=False): self._write = get_write_function(output, overwrite) self.watch = [ v if isinstance(v, BaseVariable) else CommonVariable(v) for v in utils.ensure_tuple(watch) ] + [ v if isinstance(v, BaseVariable) else Exploding(v) for v in utils.ensure_tuple(watch_explode) ] self.frame_to_local_reprs = {} self.start_times = {} self.depth = depth self.prefix = prefix self.thread_info = thread_info self.thread_info_padding = 0 assert self.depth >= 1 self.target_codes = set() self.target_frames = set() self.thread_local = threading.local() if len(custom_repr) == 2 and not all(isinstance(x, pycompat.collections_abc.Iterable) for x in custom_repr): custom_repr = (custom_repr,) self.custom_repr = custom_repr self.last_source_path = None self.max_variable_length = max_variable_length self.normalize = normalize self.relative_time = relative_time
true
2
436
pysnooper
pysnooper.tracer
Tracer
__call__
def __call__(self, function_or_class): if DISABLED: return function_or_class if inspect.isclass(function_or_class): return self._wrap_class(function_or_class) else: return self._wrap_function(function_or_class)
[ 236, 243 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) class Tracer: def __init__(self, output=None, watch=(), watch_explode=(), depth=1, prefix='', overwrite=False, thread_info=False, custom_repr=(), max_variable_length=100, normalize=False, relative_time=False): self._write = get_write_function(output, overwrite) self.watch = [ v if isinstance(v, BaseVariable) else CommonVariable(v) for v in utils.ensure_tuple(watch) ] + [ v if isinstance(v, BaseVariable) else Exploding(v) for v in utils.ensure_tuple(watch_explode) ] self.frame_to_local_reprs = {} self.start_times = {} self.depth = depth self.prefix = prefix self.thread_info = thread_info self.thread_info_padding = 0 assert self.depth >= 1 self.target_codes = set() self.target_frames = set() self.thread_local = threading.local() if len(custom_repr) == 2 and not all(isinstance(x, pycompat.collections_abc.Iterable) for x in custom_repr): custom_repr = (custom_repr,) self.custom_repr = custom_repr self.last_source_path = None self.max_variable_length = max_variable_length self.normalize = normalize self.relative_time = relative_time def __call__(self, function_or_class): if DISABLED: return function_or_class if inspect.isclass(function_or_class): return self._wrap_class(function_or_class) else: return self._wrap_function(function_or_class)
true
2
437
pysnooper
pysnooper.tracer
Tracer
__enter__
def __enter__(self): if DISABLED: return thread_global.__dict__.setdefault('depth', -1) calling_frame = inspect.currentframe().f_back if not self._is_internal_frame(calling_frame): calling_frame.f_trace = self.trace self.target_frames.add(calling_frame) stack = self.thread_local.__dict__.setdefault( 'original_trace_functions', [] ) stack.append(sys.gettrace()) self.start_times[calling_frame] = datetime_module.datetime.now() sys.settrace(self.trace)
[ 292, 306 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) class Tracer: def __init__(self, output=None, watch=(), watch_explode=(), depth=1, prefix='', overwrite=False, thread_info=False, custom_repr=(), max_variable_length=100, normalize=False, relative_time=False): self._write = get_write_function(output, overwrite) self.watch = [ v if isinstance(v, BaseVariable) else CommonVariable(v) for v in utils.ensure_tuple(watch) ] + [ v if isinstance(v, BaseVariable) else Exploding(v) for v in utils.ensure_tuple(watch_explode) ] self.frame_to_local_reprs = {} self.start_times = {} self.depth = depth self.prefix = prefix self.thread_info = thread_info self.thread_info_padding = 0 assert self.depth >= 1 self.target_codes = set() self.target_frames = set() self.thread_local = threading.local() if len(custom_repr) == 2 and not all(isinstance(x, pycompat.collections_abc.Iterable) for x in custom_repr): custom_repr = (custom_repr,) self.custom_repr = custom_repr self.last_source_path = None self.max_variable_length = max_variable_length self.normalize = normalize self.relative_time = relative_time def __enter__(self): if DISABLED: return thread_global.__dict__.setdefault('depth', -1) calling_frame = inspect.currentframe().f_back if not self._is_internal_frame(calling_frame): calling_frame.f_trace = self.trace self.target_frames.add(calling_frame) stack = self.thread_local.__dict__.setdefault( 'original_trace_functions', [] ) stack.append(sys.gettrace()) self.start_times[calling_frame] = datetime_module.datetime.now() sys.settrace(self.trace)
true
2
438
pysnooper
pysnooper.tracer
Tracer
__exit__
def __exit__(self, exc_type, exc_value, exc_traceback): if DISABLED: return stack = self.thread_local.original_trace_functions sys.settrace(stack.pop()) calling_frame = inspect.currentframe().f_back self.target_frames.discard(calling_frame) self.frame_to_local_reprs.pop(calling_frame, None) ### Writing elapsed time: ############################################# # # start_time = self.start_times.pop(calling_frame) duration = datetime_module.datetime.now() - start_time elapsed_time_string = pycompat.timedelta_format(duration) indent = ' ' * 4 * (thread_global.depth + 1) self.write( '{indent}Elapsed time: {elapsed_time_string}'.format(**locals()) ) # # ### Finished writing elapsed time. ####################################
[ 308, 323 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) class Tracer: def __init__(self, output=None, watch=(), watch_explode=(), depth=1, prefix='', overwrite=False, thread_info=False, custom_repr=(), max_variable_length=100, normalize=False, relative_time=False): self._write = get_write_function(output, overwrite) self.watch = [ v if isinstance(v, BaseVariable) else CommonVariable(v) for v in utils.ensure_tuple(watch) ] + [ v if isinstance(v, BaseVariable) else Exploding(v) for v in utils.ensure_tuple(watch_explode) ] self.frame_to_local_reprs = {} self.start_times = {} self.depth = depth self.prefix = prefix self.thread_info = thread_info self.thread_info_padding = 0 assert self.depth >= 1 self.target_codes = set() self.target_frames = set() self.thread_local = threading.local() if len(custom_repr) == 2 and not all(isinstance(x, pycompat.collections_abc.Iterable) for x in custom_repr): custom_repr = (custom_repr,) self.custom_repr = custom_repr self.last_source_path = None self.max_variable_length = max_variable_length self.normalize = normalize self.relative_time = relative_time def __exit__(self, exc_type, exc_value, exc_traceback): if DISABLED: return stack = self.thread_local.original_trace_functions sys.settrace(stack.pop()) calling_frame = inspect.currentframe().f_back self.target_frames.discard(calling_frame) self.frame_to_local_reprs.pop(calling_frame, None) ### Writing elapsed time: ############################################# # # start_time = self.start_times.pop(calling_frame) duration = datetime_module.datetime.now() - start_time elapsed_time_string = pycompat.timedelta_format(duration) indent = ' ' * 4 * (thread_global.depth + 1) self.write( '{indent}Elapsed time: {elapsed_time_string}'.format(**locals()) ) # # ### Finished writing elapsed time. ####################################
true
2
439
pysnooper
pysnooper.tracer
Tracer
trace
def trace(self, frame, event, arg): ### Checking whether we should trace this line: ####################### # # # We should trace this line either if it's in the decorated function, # or the user asked to go a few levels deeper and we're within that # number of levels deeper. if not (frame.f_code in self.target_codes or frame in self.target_frames): if self.depth == 1: # We did the most common and quickest check above, because the # trace function runs so incredibly often, therefore it's # crucial to hyper-optimize it for the common case. return None elif self._is_internal_frame(frame): return None else: _frame_candidate = frame for i in range(1, self.depth): _frame_candidate = _frame_candidate.f_back if _frame_candidate is None: return None elif _frame_candidate.f_code in self.target_codes or _frame_candidate in self.target_frames: break else: return None if event == 'call': thread_global.depth += 1 indent = ' ' * 4 * thread_global.depth # # ### Finished checking whether we should trace this line. ############## ### Making timestamp: ################################################# # # if self.normalize: timestamp = ' ' * 15 elif self.relative_time: try: start_time = self.start_times[frame] except KeyError: start_time = self.start_times[frame] = \ datetime_module.datetime.now() duration = datetime_module.datetime.now() - start_time timestamp = pycompat.timedelta_format(duration) else: timestamp = pycompat.time_isoformat( datetime_module.datetime.now().time(), timespec='microseconds' ) # # ### Finished making timestamp. ######################################## line_no = frame.f_lineno source_path, source = get_path_and_source_from_frame(frame) source_path = source_path if not self.normalize else os.path.basename(source_path) if self.last_source_path != source_path: self.write(u'{indent}Source path:... {source_path}'. format(**locals())) self.last_source_path = source_path source_line = source[line_no - 1] thread_info = "" if self.thread_info: if self.normalize: raise NotImplementedError("normalize is not supported with " "thread_info") current_thread = threading.current_thread() thread_info = "{ident}-{name} ".format( ident=current_thread.ident, name=current_thread.getName()) thread_info = self.set_thread_info_padding(thread_info) ### Reporting newish and modified variables: ########################## # # old_local_reprs = self.frame_to_local_reprs.get(frame, {}) self.frame_to_local_reprs[frame] = local_reprs = \ get_local_reprs(frame, watch=self.watch, custom_repr=self.custom_repr, max_length=self.max_variable_length, normalize=self.normalize, ) newish_string = ('Starting var:.. ' if event == 'call' else 'New var:....... ') for name, value_repr in local_reprs.items(): if name not in old_local_reprs: self.write('{indent}{newish_string}{name} = {value_repr}'.format( **locals())) elif old_local_reprs[name] != value_repr: self.write('{indent}Modified var:.. {name} = {value_repr}'.format( **locals())) # # ### Finished newish and modified variables. ########################### ### Dealing with misplaced function definition: ####################### # # if event == 'call' and source_line.lstrip().startswith('@'): # If a function decorator is found, skip lines until an actual # function definition is found. for candidate_line_no in itertools.count(line_no): try: candidate_source_line = source[candidate_line_no - 1] except IndexError: # End of source file reached without finding a function # definition. Fall back to original source line. break if candidate_source_line.lstrip().startswith('def'): # Found the def line! line_no = candidate_line_no source_line = candidate_source_line break # # ### Finished dealing with misplaced function definition. ############## # If a call ends due to an exception, we still get a 'return' event # with arg = None. This seems to be the only way to tell the difference # https://stackoverflow.com/a/12800909/2482744 code_byte = frame.f_code.co_code[frame.f_lasti] if not isinstance(code_byte, int): code_byte = ord(code_byte) ended_by_exception = ( event == 'return' and arg is None and (opcode.opname[code_byte] not in ('RETURN_VALUE', 'YIELD_VALUE')) ) if ended_by_exception: self.write('{indent}Call ended by exception'. format(**locals())) else: self.write(u'{indent}{timestamp} {thread_info}{event:9} ' u'{line_no:4} {source_line}'.format(**locals())) if event == 'return': self.frame_to_local_reprs.pop(frame, None) self.start_times.pop(frame, None) thread_global.depth -= 1 if not ended_by_exception: return_value_repr = utils.get_shortish_repr(arg, custom_repr=self.custom_repr, max_length=self.max_variable_length, normalize=self.normalize, ) self.write('{indent}Return value:.. {return_value_repr}'. format(**locals())) if event == 'exception': exception = '\n'.join(traceback.format_exception_only(*arg[:2])).strip() if self.max_variable_length: exception = utils.truncate(exception, self.max_variable_length) self.write('{indent}Exception:..... {exception}'. format(**locals())) return self.trace
[ 338, 497 ]
false
[ "ipython_filename_pattern", "source_and_path_cache", "thread_global", "DISABLED" ]
import functools import inspect import opcode import os import sys import re import collections import datetime as datetime_module import itertools import threading import traceback from .variables import CommonVariable, Exploding, BaseVariable from . import utils, pycompat ipython_filename_pattern = re.compile('^<ipython-input-([0-9]+)-.*>$') source_and_path_cache = {} thread_global = threading.local() DISABLED = bool(os.getenv('PYSNOOPER_DISABLED', '')) class Tracer: def __init__(self, output=None, watch=(), watch_explode=(), depth=1, prefix='', overwrite=False, thread_info=False, custom_repr=(), max_variable_length=100, normalize=False, relative_time=False): self._write = get_write_function(output, overwrite) self.watch = [ v if isinstance(v, BaseVariable) else CommonVariable(v) for v in utils.ensure_tuple(watch) ] + [ v if isinstance(v, BaseVariable) else Exploding(v) for v in utils.ensure_tuple(watch_explode) ] self.frame_to_local_reprs = {} self.start_times = {} self.depth = depth self.prefix = prefix self.thread_info = thread_info self.thread_info_padding = 0 assert self.depth >= 1 self.target_codes = set() self.target_frames = set() self.thread_local = threading.local() if len(custom_repr) == 2 and not all(isinstance(x, pycompat.collections_abc.Iterable) for x in custom_repr): custom_repr = (custom_repr,) self.custom_repr = custom_repr self.last_source_path = None self.max_variable_length = max_variable_length self.normalize = normalize self.relative_time = relative_time def trace(self, frame, event, arg): ### Checking whether we should trace this line: ####################### # # # We should trace this line either if it's in the decorated function, # or the user asked to go a few levels deeper and we're within that # number of levels deeper. if not (frame.f_code in self.target_codes or frame in self.target_frames): if self.depth == 1: # We did the most common and quickest check above, because the # trace function runs so incredibly often, therefore it's # crucial to hyper-optimize it for the common case. return None elif self._is_internal_frame(frame): return None else: _frame_candidate = frame for i in range(1, self.depth): _frame_candidate = _frame_candidate.f_back if _frame_candidate is None: return None elif _frame_candidate.f_code in self.target_codes or _frame_candidate in self.target_frames: break else: return None if event == 'call': thread_global.depth += 1 indent = ' ' * 4 * thread_global.depth # # ### Finished checking whether we should trace this line. ############## ### Making timestamp: ################################################# # # if self.normalize: timestamp = ' ' * 15 elif self.relative_time: try: start_time = self.start_times[frame] except KeyError: start_time = self.start_times[frame] = \ datetime_module.datetime.now() duration = datetime_module.datetime.now() - start_time timestamp = pycompat.timedelta_format(duration) else: timestamp = pycompat.time_isoformat( datetime_module.datetime.now().time(), timespec='microseconds' ) # # ### Finished making timestamp. ######################################## line_no = frame.f_lineno source_path, source = get_path_and_source_from_frame(frame) source_path = source_path if not self.normalize else os.path.basename(source_path) if self.last_source_path != source_path: self.write(u'{indent}Source path:... {source_path}'. format(**locals())) self.last_source_path = source_path source_line = source[line_no - 1] thread_info = "" if self.thread_info: if self.normalize: raise NotImplementedError("normalize is not supported with " "thread_info") current_thread = threading.current_thread() thread_info = "{ident}-{name} ".format( ident=current_thread.ident, name=current_thread.getName()) thread_info = self.set_thread_info_padding(thread_info) ### Reporting newish and modified variables: ########################## # # old_local_reprs = self.frame_to_local_reprs.get(frame, {}) self.frame_to_local_reprs[frame] = local_reprs = \ get_local_reprs(frame, watch=self.watch, custom_repr=self.custom_repr, max_length=self.max_variable_length, normalize=self.normalize, ) newish_string = ('Starting var:.. ' if event == 'call' else 'New var:....... ') for name, value_repr in local_reprs.items(): if name not in old_local_reprs: self.write('{indent}{newish_string}{name} = {value_repr}'.format( **locals())) elif old_local_reprs[name] != value_repr: self.write('{indent}Modified var:.. {name} = {value_repr}'.format( **locals())) # # ### Finished newish and modified variables. ########################### ### Dealing with misplaced function definition: ####################### # # if event == 'call' and source_line.lstrip().startswith('@'): # If a function decorator is found, skip lines until an actual # function definition is found. for candidate_line_no in itertools.count(line_no): try: candidate_source_line = source[candidate_line_no - 1] except IndexError: # End of source file reached without finding a function # definition. Fall back to original source line. break if candidate_source_line.lstrip().startswith('def'): # Found the def line! line_no = candidate_line_no source_line = candidate_source_line break # # ### Finished dealing with misplaced function definition. ############## # If a call ends due to an exception, we still get a 'return' event # with arg = None. This seems to be the only way to tell the difference # https://stackoverflow.com/a/12800909/2482744 code_byte = frame.f_code.co_code[frame.f_lasti] if not isinstance(code_byte, int): code_byte = ord(code_byte) ended_by_exception = ( event == 'return' and arg is None and (opcode.opname[code_byte] not in ('RETURN_VALUE', 'YIELD_VALUE')) ) if ended_by_exception: self.write('{indent}Call ended by exception'. format(**locals())) else: self.write(u'{indent}{timestamp} {thread_info}{event:9} ' u'{line_no:4} {source_line}'.format(**locals())) if event == 'return': self.frame_to_local_reprs.pop(frame, None) self.start_times.pop(frame, None) thread_global.depth -= 1 if not ended_by_exception: return_value_repr = utils.get_shortish_repr(arg, custom_repr=self.custom_repr, max_length=self.max_variable_length, normalize=self.normalize, ) self.write('{indent}Return value:.. {return_value_repr}'. format(**locals())) if event == 'exception': exception = '\n'.join(traceback.format_exception_only(*arg[:2])).strip() if self.max_variable_length: exception = utils.truncate(exception, self.max_variable_length) self.write('{indent}Exception:..... {exception}'. format(**locals())) return self.trace
true
2
440
pysnooper
pysnooper.utils
shitcode
def shitcode(s): return ''.join( (c if (0 < ord(c) < 256) else '?') for c in s )
[ 43, 44 ]
false
[ "file_reading_errors", "DEFAULT_REPR_RE" ]
import abc import re import sys from .pycompat import ABC, string_types, collections_abc file_reading_errors = ( IOError, OSError, ValueError # IronPython weirdness. ) DEFAULT_REPR_RE = re.compile(r' at 0x[a-f0-9A-F]{4,}') def shitcode(s): return ''.join( (c if (0 < ord(c) < 256) else '?') for c in s )
false
0
441
pysnooper
pysnooper.utils
get_repr_function
def get_repr_function(item, custom_repr): for condition, action in custom_repr: if isinstance(condition, type): condition = lambda x, y=condition: isinstance(x, y) if condition(item): return action return repr
[ 49, 55 ]
false
[ "file_reading_errors", "DEFAULT_REPR_RE" ]
import abc import re import sys from .pycompat import ABC, string_types, collections_abc file_reading_errors = ( IOError, OSError, ValueError # IronPython weirdness. ) DEFAULT_REPR_RE = re.compile(r' at 0x[a-f0-9A-F]{4,}') def get_repr_function(item, custom_repr): for condition, action in custom_repr: if isinstance(condition, type): condition = lambda x, y=condition: isinstance(x, y) if condition(item): return action return repr
true
2
442
pysnooper
pysnooper.utils
get_shortish_repr
def get_shortish_repr(item, custom_repr=(), max_length=None, normalize=False): repr_function = get_repr_function(item, custom_repr) try: r = repr_function(item) except Exception: r = 'REPR FAILED' r = r.replace('\r', '').replace('\n', '') if normalize: r = normalize_repr(r) if max_length: r = truncate(r, max_length) return r
[ 66, 77 ]
false
[ "file_reading_errors", "DEFAULT_REPR_RE" ]
import abc import re import sys from .pycompat import ABC, string_types, collections_abc file_reading_errors = ( IOError, OSError, ValueError # IronPython weirdness. ) DEFAULT_REPR_RE = re.compile(r' at 0x[a-f0-9A-F]{4,}') def get_shortish_repr(item, custom_repr=(), max_length=None, normalize=False): repr_function = get_repr_function(item, custom_repr) try: r = repr_function(item) except Exception: r = 'REPR FAILED' r = r.replace('\r', '').replace('\n', '') if normalize: r = normalize_repr(r) if max_length: r = truncate(r, max_length) return r
true
2
443
pysnooper
pysnooper.utils
truncate
def truncate(string, max_length): if (max_length is None) or (len(string) <= max_length): return string else: left = (max_length - 3) // 2 right = max_length - 3 - left return u'{}...{}'.format(string[:left], string[-right:])
[ 80, 86 ]
false
[ "file_reading_errors", "DEFAULT_REPR_RE" ]
import abc import re import sys from .pycompat import ABC, string_types, collections_abc file_reading_errors = ( IOError, OSError, ValueError # IronPython weirdness. ) DEFAULT_REPR_RE = re.compile(r' at 0x[a-f0-9A-F]{4,}') def truncate(string, max_length): if (max_length is None) or (len(string) <= max_length): return string else: left = (max_length - 3) // 2 right = max_length - 3 - left return u'{}...{}'.format(string[:left], string[-right:])
true
2
444
pysnooper
pysnooper.utils
WritableStream
write
@abc.abstractmethod def write(self, s): pass
[ 24, 25 ]
false
[ "file_reading_errors", "DEFAULT_REPR_RE" ]
import abc import re import sys from .pycompat import ABC, string_types, collections_abc file_reading_errors = ( IOError, OSError, ValueError # IronPython weirdness. ) DEFAULT_REPR_RE = re.compile(r' at 0x[a-f0-9A-F]{4,}') class WritableStream(ABC): @abc.abstractmethod def write(self, s): pass
false
0