-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add partial stubs for fractions #544
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Stubs for fractions | ||
# See https://docs.python.org/3/library/fractions.html | ||
# | ||
# Note: these stubs are incomplete. The more complex type | ||
# signatures are currently omitted. Also see numbers.pyi. | ||
|
||
from typing import Optional, TypeVar, Union, overload | ||
from numbers import Real, Integral, Rational | ||
from decimal import Decimal | ||
import sys | ||
|
||
_ComparableNum = Union[int, float, Decimal, Real] | ||
|
||
|
||
@overload | ||
def gcd(a: int, b: int) -> int: ... | ||
@overload | ||
def gcd(a: Integral, b: int) -> Integral: ... | ||
@overload | ||
def gcd(a: int, b: Integral) -> Integral: ... | ||
@overload | ||
def gcd(a: Integral, b: Integral) -> Integral: ... | ||
|
||
|
||
class Fraction(Rational): | ||
@overload | ||
def __init__(self, | ||
numerator: Union[int, Rational] = 0, | ||
denominator: Optional[Union[int, Rational]] = 0, | ||
*, | ||
_normalize: bool = True) -> None: ... | ||
@overload | ||
def __init__(self, value: float, *, _normalize=True) -> None: ... | ||
@overload | ||
def __init__(self, value: Decimal, *, _normalize=True) -> None: ... | ||
@overload | ||
def __init__(self, value: str, *, _normalize=True) -> None: ... | ||
|
||
@classmethod | ||
def from_float(cls, f: float) -> 'Fraction': ... | ||
@classmethod | ||
def from_decimal(cls, dec: Decimal) -> 'Fraction': ... | ||
def limit_denominator(self, max_denominator: int = 1000000) -> 'Fraction': ... | ||
|
||
@property | ||
def numerator(self) -> int: ... | ||
@property | ||
def denominator(self) -> int: ... | ||
|
||
def __add__(self, other): ... | ||
def __radd__(self, other): ... | ||
def __sub__(self, other): ... | ||
def __rsub__(self, other): ... | ||
def __mul__(self, other): ... | ||
def __rmul__(self, other): ... | ||
def __truediv__(self, other): ... | ||
def __rtruediv__(self, other): ... | ||
if sys.version_info < (3, 0): | ||
def __div__(self, other): ... | ||
def __rdiv__(self, other): ... | ||
def __floordiv__(self, other) -> int: ... | ||
def __rfloordiv__(self, other) -> int: ... | ||
def __mod__(self, other): ... | ||
def __rmod__(self, other): ... | ||
def __pow__(self, other): ... | ||
def __rpow__(self, other): ... | ||
|
||
def __pos__(self) -> 'Fraction': ... | ||
def __neg__(self) -> 'Fraction': ... | ||
def __abs__(self) -> 'Fraction': ... | ||
def __trunc__(self) -> int: ... | ||
if sys.version_info >= (3, 0): | ||
def __floor__(self) -> int: ... | ||
def __ceil__(self) -> int: ... | ||
def __round__(self, ndigits=None): ... | ||
|
||
def __hash__(self) -> int: ... | ||
def __eq__(self, other: object) -> bool: ... | ||
def __lt__(self, other: _ComparableNum) -> bool: ... | ||
def __gt__(self, other: _ComparableNum) -> bool: ... | ||
def __le__(self, other: _ComparableNum) -> bool: ... | ||
def __ge__(self, other: _ComparableNum) -> bool: ... | ||
if sys.version_info >= (3, 0): | ||
def __bool__(self) -> bool: ... | ||
else: | ||
def __nonzero__(self) -> bool: ... | ||
|
||
# Not actually defined within fractions.py, but provides more useful | ||
# overrides | ||
@property | ||
def real(self) -> 'Fraction': ... | ||
@property | ||
def imag(self) -> 'Fraction': ... | ||
def conjugate(self) -> 'Fraction': ... |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a # TODO comment here asking for better annotations in the future?