| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 380f7f2 commit 9e7f1d2
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -327,7 +327,7 @@ loops that truncate the stream. | |||
| 327 | 327 | example :func:`islice` or :func:`takewhile`). | |
| 328 | 328 | ||
| 329 | 329 | ||
| 330 | - .. function:: product(*iterables) | ||
| 330 | + .. function:: product(*iterables[, repeat]) | ||
| 331 | 331 | ||
| 332 | 332 | Cartesian product of input iterables. | |
| 333 | 333 | ||
@@ -340,11 +340,15 @@ loops that truncate the stream. | |||
| 340 | 340 | so that if the inputs iterables are sorted, the product tuples are emitted | |
| 341 | 341 | in sorted order. | |
| 342 | 342 | ||
| 343 | + To compute the product of an iterable with itself, specify the number of | ||
| 344 | + repetitions with the optional *repeat* keyword argument. For example, | ||
| 345 | + ``product(A, repeat=4)`` means the same as ``product(A, A, A, A)``. | ||
| 346 | + | ||
| 343 | 347 | Equivalent to the following except that the actual implementation does not | |
| 344 | 348 | build-up intermediate results in memory:: | |
| 345 | 349 | ||
| 346 | - def product(*args): | ||
| 347 | - pools = map(tuple, args) | ||
| 350 | + def product(*args, **kwds): | ||
| 351 | + pools = map(tuple, args) * kwds.get('repeat', 1) | ||
| 348 | 352 | if pools: | |
| 349 | 353 | result = [[]] | |
| 350 | 354 | for pool in pools: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -532,6 +532,9 @@ given type object has a specified feature. | |||
| 532 | 532 | #define Py_TPFLAGS_HAVE_VERSION_TAG (1L<<18) | |
| 533 | 533 | #define Py_TPFLAGS_VALID_VERSION_TAG (1L<<19) | |
| 534 | 534 | ||
| 535 | + /* Type is abstract and cannot be instantiated */ | ||
| 536 | + #define Py_TPFLAGS_IS_ABSTRACT (1L<<20) | ||
| 537 | + | ||
| 535 | 538 | /* These flags are used to determine if a type is a subclass. */ | |
| 536 | 539 | #define Py_TPFLAGS_INT_SUBCLASS (1L<<23) | |
| 537 | 540 | #define Py_TPFLAGS_LONG_SUBCLASS (1L<<24) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,50 +52,6 @@ def setx(self, value): ... | |||
| 52 | 52 | __isabstractmethod__ = True | |
| 53 | 53 | ||
| 54 | 54 | ||
| 55 | - class _Abstract(object): | ||
| 56 | - | ||
| 57 | - """Helper class inserted into the bases by ABCMeta (using _fix_bases()). | ||
| 58 | - | ||
| 59 | - You should never need to explicitly subclass this class. | ||
| 60 | - """ | ||
| 61 | - | ||
| 62 | - def __new__(cls, *args, **kwds): | ||
| 63 | - am = cls.__dict__.get("__abstractmethods__") | ||
| 64 | - if am: | ||
| 65 | - raise TypeError("Can't instantiate abstract class %s " | ||
| 66 | - "with abstract methods %s" % | ||
| 67 | - (cls.__name__, ", ".join(sorted(am)))) | ||
| 68 | - if (args or kwds) and cls.__init__ is object.__init__: | ||
| 69 | - raise TypeError("Can't pass arguments to __new__ " | ||
| 70 | - "without overriding __init__") | ||
| 71 | - return super().__new__(cls) | ||
| 72 | - | ||
| 73 | - @classmethod | ||
| 74 | - def __subclasshook__(cls, subclass): | ||
| 75 | - """Abstract classes can override this to customize issubclass(). | ||
| 76 | - | ||
| 77 | - This is invoked early on by __subclasscheck__() below. It | ||
| 78 | - should return True, False or NotImplemented. If it returns | ||
| 79 | - NotImplemented, the normal algorithm is used. Otherwise, it | ||
| 80 | - overrides the normal algorithm (and the outcome is cached). | ||
| 81 | - """ | ||
| 82 | - return NotImplemented | ||
| 83 | - | ||
| 84 | - | ||
| 85 | - def _fix_bases(bases): | ||
| 86 | - """Helper method that inserts _Abstract in the bases if needed.""" | ||
| 87 | - for base in bases: | ||
| 88 | - if issubclass(base, _Abstract): | ||
| 89 | - # _Abstract is already a base (maybe indirectly) | ||
| 90 | - return bases | ||
| 91 | - if object in bases: | ||
| 92 | - # Replace object with _Abstract | ||
| 93 | - return tuple([_Abstract if base is object else base | ||
| 94 | - for base in bases]) | ||
| 95 | - # Append _Abstract to the end | ||
| 96 | - return bases + (_Abstract,) | ||
| 97 | - | ||
| 98 | - | ||
| 99 | 55 | class ABCMeta(type): | |
| 100 | 56 | ||
| 101 | 57 | """Metaclass for defining Abstract Base Classes (ABCs). | |
@@ -118,7 +74,6 @@ class ABCMeta(type): | |||
| 118 | 74 | _abc_invalidation_counter = 0 | |
| 119 | 75 | ||
| 120 | 76 | def __new__(mcls, name, bases, namespace): | |
| 121 | - bases = _fix_bases(bases) | ||
| 122 | 77 | cls = super().__new__(mcls, name, bases, namespace) | |
| 123 | 78 | # Compute set of abstract method names | |
| 124 | 79 | abstracts = {name | |
@@ -129,7 +84,7 @@ def __new__(mcls, name, bases, namespace): | |||
| 129 | 84 | value = getattr(cls, name, None) | |
| 130 | 85 | if getattr(value, "__isabstractmethod__", False): | |
| 131 | 86 | abstracts.add(name) | |
| 132 | - cls.__abstractmethods__ = abstracts | ||
| 87 | + cls.__abstractmethods__ = frozenset(abstracts) | ||
| 133 | 88 | # Set up inheritance registry | |
| 134 | 89 | cls._abc_registry = WeakSet() | |
| 135 | 90 | cls._abc_cache = WeakSet() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1649,6 +1649,9 @@ def _round_down(self, prec): | |||
| 1649 | 1649 | else: | |
| 1650 | 1650 | return -1 | |
| 1651 | 1651 | ||
| 1652 | + def __round__(self): | ||
| 1653 | + return self._round_down(0) | ||
| 1654 | + | ||
| 1652 | 1655 | def _round_up(self, prec): | |
| 1653 | 1656 | """Rounds away from 0.""" | |
| 1654 | 1657 | return -self._round_down(prec) | |
@@ -1684,13 +1687,19 @@ def _round_ceiling(self, prec): | |||
| 1684 | 1687 | else: | |
| 1685 | 1688 | return -self._round_down(prec) | |
| 1686 | 1689 | ||
| 1690 | + def __ceil__(self): | ||
| 1691 | + return self._round_ceiling(0) | ||
| 1692 | + | ||
| 1687 | 1693 | def _round_floor(self, prec): | |
| 1688 | 1694 | """Rounds down (not towards 0 if negative)""" | |
| 1689 | 1695 | if not self._sign: | |
| 1690 | 1696 | return self._round_down(prec) | |
| 1691 | 1697 | else: | |
| 1692 | 1698 | return -self._round_down(prec) | |
| 1693 | 1699 | ||
| 1700 | + def __floor__(self): | ||
| 1701 | + return self._round_floor(0) | ||
| 1702 | + | ||
| 1694 | 1703 | def _round_05up(self, prec): | |
| 1695 | 1704 | """Round down unless digit prec-1 is 0 or 5.""" | |
| 1696 | 1705 | if prec and self._int[prec-1] not in '05': | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -196,6 +196,7 @@ def merge(self, other): | |||
| 196 | 196 | '__setattr__', | |
| 197 | 197 | '__setitem__', | |
| 198 | 198 | '__str__', | |
| 199 | + '__subclasshook__', | ||
| 199 | 200 | 'append', | |
| 200 | 201 | 'count', | |
| 201 | 202 | 'extend', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments