| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9d0d616 commit 68f5fbe
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,24 @@ Rational number class. | |||
| 46 | 46 | :class:`decimal.Decimal`. | |
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | + .. method:: Fraction.limit_denominator(max_denominator=1000000) | ||
| 50 | + | ||
| 51 | + Finds and returns the closest :class:`Fraction` to ``self`` that | ||
| 52 | + has denominator at most max_denominator. This method is useful for | ||
| 53 | + finding rational approximations to a given floating-point number:: | ||
| 54 | + | ||
| 55 | + >>> Fraction('3.1415926535897932').limit_denominator(1000) | ||
| 56 | + Fraction(355, 113) | ||
| 57 | + | ||
| 58 | + or for recovering a rational number that's represented as a float:: | ||
| 59 | + | ||
| 60 | + >>> from math import pi, cos | ||
| 61 | + >>> Fraction.from_float(cos(pi/3)) | ||
| 62 | + Fraction(4503599627370497L, 9007199254740992L) | ||
| 63 | + >>> Fraction.from_float(cos(pi/3)).limit_denominator() | ||
| 64 | + Fraction(1, 2) | ||
| 65 | + | ||
| 66 | + | ||
| 49 | 67 | .. method:: Fraction.__floor__() | |
| 50 | 68 | ||
| 51 | 69 | Returns the greatest :class:`int` ``<= self``. Will be accessible | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1584,7 +1584,7 @@ written in Python, such as a mail server's external command delivery program. | |||
| 1584 | 1584 | user time, children's system time, and elapsed real time since a fixed point in | |
| 1585 | 1585 | the past, in that order. See the Unix manual page :manpage:`times(2)` or the | |
| 1586 | 1586 | corresponding Windows Platform API documentation. Availability: Macintosh, Unix, | |
| 1587 | - Windows. | ||
| 1587 | + Windows. On Windows, only the first two items are filled, the others are zero. | ||
| 1588 | 1588 | ||
| 1589 | 1589 | ||
| 1590 | 1590 | .. function:: wait() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,8 +162,19 @@ def _dump_registry(cls, file=None): | |||
| 162 | 162 | ||
| 163 | 163 | def __instancecheck__(cls, instance): | |
| 164 | 164 | """Override for isinstance(instance, cls).""" | |
| 165 | - return any(cls.__subclasscheck__(c) | ||
| 166 | - for c in {instance.__class__, type(instance)}) | ||
| 165 | + # Inline the cache checking | ||
| 166 | + subclass = instance.__class__ | ||
| 167 | + if subclass in cls._abc_cache: | ||
| 168 | + return True | ||
| 169 | + subtype = type(instance) | ||
| 170 | + if subtype is subclass: | ||
| 171 | + if (cls._abc_negative_cache_version == | ||
| 172 | + ABCMeta._abc_invalidation_counter and | ||
| 173 | + subclass in cls._abc_negative_cache): | ||
| 174 | + return False | ||
| 175 | + # Fall back to the subclass check. | ||
| 176 | + return cls.__subclasscheck__(subclass) | ||
| 177 | + return any(cls.__subclasscheck__(c) for c in {subclass, subtype}) | ||
| 167 | 178 | ||
| 168 | 179 | def __subclasscheck__(cls, subclass): | |
| 169 | 180 | """Override for issubclass(subclass, cls).""" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments