8000 Stub for fractions by youtux · Pull Request #94 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Stub for fractions #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions stdlib/2and3/fractions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from typing import overload, Union, TypeVar

import numbers
import decimal

Number_ish = Union[int, float, str, numbers.Rational, decimal.Decimal]

UpToComplexT = TypeVar('UpToComplexT', numbers.Rational,
numbers.Real, numbers.Complex)
UpToRealT = TypeVar('UpToRealT', numbers.Rational, numbers.Real)

class Fraction(numbers.Rational):
@overload
def __init__(self, numerator: numbers.Rational = ...,
denominator: numbers.Rational = ...,
_normalize: bool = ...) -> None: ...

@overload
def __init__(self, number: Number_ish) -> None: ...

@classmethod
def from_float(flt: float) -> Fraction: ...

@classmethod
def from_decimal(dec: decimal.Decimal) -> Fraction: ...

def limit_denominator(max_denominator: int = ...) -> Fraction: ...

def __add__(self, other: UpToComplexT) -> UpToComplexT: ...
def __radd__(self, other: UpToComplexT) -> UpToComplexT: ...
def __sub__(self, other: UpToComplexT) -> UpToComplexT: ...
def __rsub__(self, other: UpToComplexT) -> UpToComplexT: ...
def __mul__(self, other: UpToComplexT) -> UpToComplexT: ...
def __rmul__(self, other: UpToComplexT) -> UpToComplexT: ...
def __truediv__(self, other: UpToComplexT) -> UpToComplexT: ...
def __rtruediv__(self, other: UpToComplexT) -> UpToComplexT: ...
def __floordiv__(self, other: UpToComplexT) -> numbers.Integral: ...
def __rfloordiv__(self, other: UpToComplexT) -> numbers.Integral: ...

def __mod__(self, other: UpToRealT) -> UpToRealT: ...
def __rmod__(self, other: UpToRealT) -> UpToRealT: ...

@overload
def __pow__(self, other: numbers.Integral) -> Fraction: ...
@overload
def __pow__(self, other: numbers.Complex) -> numbers.Complex: ...

def __rpow__(self, other: numbers.Complex) -> numbers.Complex: ...
def __pos__(self) -> Fraction: ...
def __neg__(self) -> Fraction: ...
def __abs__(self) -> Fraction: ...

# TODO: __floor__, __ceil__ and __round__ are Python 3 only
def __floor__(self) -> int: ...
def __ceil__(self) -> int: ...
def __round__(self, ndigits: int = ...) -> Fraction: ...


def gcd(a: int, b: int) -> int: ...
0