| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -205,7 +205,7 @@ Module contents | |||
| 205 | 205 | follows a field with a default value. This is true whether this | |
| 206 | 206 | occurs in a single class, or as a result of class inheritance. | |
| 207 | 207 | ||
| 208 | - .. function:: field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=MISSING): | ||
| 208 | + .. function:: field(*, default=MISSING, default_factory=MISSING, init=True, repr=True, hash=None, compare=True, metadata=None, kw_only=MISSING) | ||
| 209 | 209 | ||
| 210 | 210 | For common and simple use cases, no other functionality is | |
| 211 | 211 | required. There are, however, some dataclass features that | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -824,10 +824,20 @@ form. | |||
| 824 | 824 | .. function:: findall(pattern, string, flags=0) | |
| 825 | 825 | ||
| 826 | 826 | Return all non-overlapping matches of *pattern* in *string*, as a list of | |
| 827 | - strings. The *string* is scanned left-to-right, and matches are returned in | ||
| 828 | - the order found. If one or more groups are present in the pattern, return a | ||
| 829 | - list of groups; this will be a list of tuples if the pattern has more than | ||
| 830 | - one group. Empty matches are included in the result. | ||
| 827 | + strings or tuples. The *string* is scanned left-to-right, and matches | ||
| 828 | + are returned in the order found. Empty matches are included in the result. | ||
| 829 | + | ||
| 830 | + The result depends on the number of capturing groups in the pattern. | ||
| 831 | + If there are no groups, return a list of strings matching the whole | ||
| 832 | + pattern. If there is exactly one group, return a list of strings | ||
| 833 | + matching that group. If multiple groups are present, return a list | ||
| 834 | + of tuples of strings matching the groups. Non-capturing groups do not | ||
| 835 | + affect the form of the result. | ||
| 836 | + | ||
| 837 | + >>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') | ||
| 838 | + ['foot', 'fell', 'fastest'] | ||
| 839 | + >>> re.findall(r'(\w+)=(\d+)', 'set width=20 and height=10') | ||
| 840 | + [('width', '20'), ('height', '10')] | ||
| 831 | 841 | ||
| 832 | 842 | .. versionchanged:: 3.7 | |
| 833 | 843 | Non-empty matches can now start just after a previous empty match. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2013,6 +2013,13 @@ Introspection helpers | |||
| 2013 | 2013 | 'name': Annotated[str, 'some marker'] | |
| 2014 | 2014 | } | |
| 2015 | 2015 | ||
| 2016 | + .. note:: | ||
| 2017 | + | ||
| 2018 | + :func:`get_type_hints` does not work with imported | ||
| 2019 | + :ref:`type aliases <type-aliases>` that include forward references. | ||
| 2020 | + Enabling postponed evaluation of annotations (:pep:`563`) may remove | ||
| 2021 | + the need for most forward references. | ||
| 2022 | + | ||
| 2016 | 2023 | .. versionchanged:: 3.9 | |
| 2017 | 2024 | Added ``include_extras`` parameter as part of :pep:`593`. | |
| 2018 | 2025 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,7 +53,7 @@ programs, however, and result in error messages as shown here:: | |||
| 53 | 53 | >>> '2' + 2 | |
| 54 | 54 | Traceback (most recent call last): | |
| 55 | 55 | File "<stdin>", line 1, in <module> | |
| 56 | - TypeError: Can't convert 'int' object to str implicitly | ||
| 56 | + TypeError: can only concatenate str (not "int") to str | ||
| 57 | 57 | ||
| 58 | 58 | The last line of the error message indicates what happened. Exceptions come in | |
| 59 | 59 | different types, and the type is printed as part of the message: the types in | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1971,10 +1971,11 @@ def test_subprocess_wait_no_same_group(self): | |||
| 1971 | 1971 | functools.partial(MySubprocessProtocol, self.loop), | |
| 1972 | 1972 | 'exit 7', stdin=None, stdout=None, stderr=None, | |
| 1973 | 1973 | start_new_session=True) | |
| 1974 | - _, proto = yield self.loop.run_until_complete(connect) | ||
| 1974 | + transp, proto = self.loop.run_until_complete(connect) | ||
| 1975 | 1975 | self.assertIsInstance(proto, MySubprocessProtocol) | |
| 1976 | 1976 | self.loop.run_until_complete(proto.completed) | |
| 1977 | 1977 | self.assertEqual(7, proto.returncode) | |
| 1978 | + transp.close() | ||
| 1978 | 1979 | ||
| 1979 | 1980 | def test_subprocess_exec_invalid_args(self): | |
| 1980 | 1981 | async def connect(**kwds): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1468,6 +1468,20 @@ def test_from_hex(self): | |||
| 1468 | 1468 | self.identical(fromHex('0X1.0000000000001fp0'), 1.0+2*EPS) | |
| 1469 | 1469 | self.identical(fromHex('0x1.00000000000020p0'), 1.0+2*EPS) | |
| 1470 | 1470 | ||
| 1471 | + # Regression test for a corner-case bug reported in b.p.o. 44954 | ||
| 1472 | + self.identical(fromHex('0x.8p-1074'), 0.0) | ||
| 1473 | + self.identical(fromHex('0x.80p-1074'), 0.0) | ||
| 1474 | + self.identical(fromHex('0x.81p-1074'), TINY) | ||
| 1475 | + self.identical(fromHex('0x8p-1078'), 0.0) | ||
| 1476 | + self.identical(fromHex('0x8.0p-1078'), 0.0) | ||
| 1477 | + self.identical(fromHex('0x8.1p-1078'), TINY) | ||
| 1478 | + self.identical(fromHex('0x80p-1082'), 0.0) | ||
| 1479 | + self.identical(fromHex('0x81p-1082'), TINY) | ||
| 1480 | + self.identical(fromHex('.8p-1074'), 0.0) | ||
| 1481 | + self.identical(fromHex('8p-1078'), 0.0) | ||
| 1482 | + self.identical(fromHex('-.8p-1074'), -0.0) | ||
| 1483 | + self.identical(fromHex('+8p-1078'), 0.0) | ||
| 1484 | + | ||
| 1471 | 1485 | def test_roundtrip(self): | |
| 1472 | 1486 | def roundtrip(x): | |
| 1473 | 1487 | return fromHex(toHex(x)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2263,6 +2263,22 @@ def test_special_values(self): | |||
| 2263 | 2263 | with self.assertRaises(ValueError): | |
| 2264 | 2264 | geometric_mean([Inf, -Inf]) | |
| 2265 | 2265 | ||
| 2266 | + def test_mixed_int_and_float(self): | ||
| 2267 | + # Regression test for b.p.o. issue #28327 | ||
| 2268 | + geometric_mean = statistics.geometric_mean | ||
| 2269 | + expected_mean = 3.80675409583932 | ||
| 2270 | + values = [ | ||
| 2271 | + [2, 3, 5, 7], | ||
| 2272 | + [2, 3, 5, 7.0], | ||
| 2273 | + [2, 3, 5.0, 7.0], | ||
| 2274 | + [2, 3.0, 5.0, 7.0], | ||
| 2275 | + [2.0, 3.0, 5.0, 7.0], | ||
| 2276 | + ] | ||
| 2277 | + for v in values: | ||
| 2278 | + with self.subTest(v=v): | ||
| 2279 | + actual_mean = geometric_mean(v) | ||
| 2280 | + self.assertAlmostEqual(actual_mean, expected_mean, places=5) | ||
| 2281 | + | ||
| 2266 | 2282 | ||
| 2267 | 2283 | class TestQuantiles(unittest.TestCase): | |
| 2268 | 2284 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4929,7 +4929,6 @@ def test_special_attrs(self): | |||
| 4929 | 4929 | self.assertEqual(cls.__name__, name, str(cls)) | |
| 4930 | 4930 | self.assertEqual(cls.__qualname__, name, str(cls)) | |
| 4931 | 4931 | self.assertEqual(cls.__module__, 'typing', str(cls)) | |
| 4932 | - self.assertEqual(getattr(cls, '_name', name), name, str(cls)) | ||
| 4933 | 4932 | for proto in range(pickle.HIGHEST_PROTOCOL + 1): | |
| 4934 | 4933 | s = pickle.dumps(cls, proto) | |
| 4935 | 4934 | loaded = pickle.loads(s) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -461,7 +461,7 @@ class Starship: | |||
| 461 | 461 | be used with isinstance() or issubclass(). | |
| 462 | 462 | """ | |
| 463 | 463 | item = _type_check(parameters, f'{self} accepts only single type.') | |
| 464 | - return _GenericAlias(self, (item,), name="ClassVar") | ||
| 464 | + return _GenericAlias(self, (item,)) | ||
| 465 | 465 | ||
| 466 | 466 | @_SpecialForm | |
| 467 | 467 | def Final(self, parameters): | |
@@ -482,7 +482,7 @@ class FastConnector(Connection): | |||
| 482 | 482 | There is no runtime checking of these properties. | |
| 483 | 483 | """ | |
| 484 | 484 | item = _type_check(parameters, f'{self} accepts only single type.') | |
| 485 | - return _GenericAlias(self, (item,), name="Final") | ||
| 485 | + return _GenericAlias(self, (item,)) | ||
| 486 | 486 | ||
| 487 | 487 | @_SpecialForm | |
| 488 | 488 | def Union(self, parameters): | |
@@ -520,12 +520,9 @@ def Union(self, parameters): | |||
| 520 | 520 | parameters = _remove_dups_flatten(parameters) | |
| 521 | 521 | if len(parameters) == 1: | |
| 522 | 522 | return parameters[0] | |
| 523 | - | ||
| 524 | 523 | if len(parameters) == 2 and type(None) in parameters: | |
| 525 | - name = "Optional" | ||
| 526 | - else: | ||
| 527 | - name = "Union" | ||
| 528 | - return _UnionGenericAlias(self, parameters, name=name) | ||
| 524 | + return _UnionGenericAlias(self, parameters, name="Optional") | ||
| 525 | + return _UnionGenericAlias(self, parameters) | ||
| 529 | 526 | ||
| 530 | 527 | @_SpecialForm | |
| 531 | 528 | def Optional(self, parameters): | |
@@ -570,7 +567,7 @@ def open_helper(file: str, mode: MODE) -> str: | |||
| 570 | 567 | except TypeError: # unhashable parameters | |
| 571 | 568 | pass | |
| 572 | 569 | ||
| 573 | - return _LiteralGenericAlias(self, parameters, name="Literal") | ||
| 570 | + return _LiteralGenericAlias(self, parameters) | ||
| 574 | 571 | ||
| 575 | 572 | ||
| 576 | 573 | @_SpecialForm | |
@@ -609,7 +606,7 @@ def Concatenate(self, parameters): | |||
| 609 | 606 | "ParamSpec variable.") | |
| 610 | 607 | msg = "Concatenate[arg, ...]: each arg must be a type." | |
| 611 | 608 | parameters = tuple(_type_check(p, msg) for p in parameters) | |
| 612 | - return _ConcatenateGenericAlias(self, parameters, name="Concatenate") | ||
| 609 | + return _ConcatenateGenericAlias(self, parameters) | ||
| 613 | 610 | ||
| 614 | 611 | ||
| 615 | 612 | @_SpecialForm | |
@@ -657,7 +654,7 @@ def is_str(val: Union[str, float]): | |||
| 657 | 654 | PEP 647 (User-Defined Type Guards). | |
| 658 | 655 | """ | |
| 659 | 656 | item = _type_check(parameters, f'{self} accepts only single type.') | |
| 660 | - return _GenericAlias(self, (item,), name="TypeGuard") | ||
| 657 | + return _GenericAlias(self, (item,)) | ||
| 661 | 658 | ||
| 662 | 659 | ||
| 663 | 660 | class ForwardRef(_Final, _root=True): | |
@@ -962,7 +959,7 @@ def __mro_entries__(self, bases): | |||
| 962 | 959 | ||
| 963 | 960 | def __getattr__(self, attr): | |
| 964 | 961 | if attr in {'__name__', '__qualname__'}: | |
| 965 | - return self._name | ||
| 962 | + return self._name or self.__origin__.__name__ | ||
| 966 | 963 | ||
| 967 | 964 | # We are careful for copy and pickle. | |
| 968 | 965 | # Also for simplicity we just don't relay all dunder names | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -557,73 +557,71 @@ def _callCleanup(self, function, /, *args, **kwargs): | |||
| 557 | 557 | function(*args, **kwargs) | |
| 558 | 558 | ||
| 559 | 559 | def run(self, result=None): | |
| 560 | - orig_result = result | ||
| 561 | 560 | if result is None: | |
| 562 | 561 | result = self.defaultTestResult() | |
| 563 | 562 | startTestRun = getattr(result, 'startTestRun', None) | |
| 563 | + stopTestRun = getattr(result, 'stopTestRun', None) | ||
| 564 | 564 | if startTestRun is not None: | |
| 565 | 565 | startTestRun() | |
| 566 | + else: | ||
| 567 | + stopTestRun = None | ||
| 566 | 568 | ||
| 567 | 569 | result.startTest(self) | |
| 568 | - | ||
| 569 | - testMethod = getattr(self, self._testMethodName) | ||
| 570 | - if (getattr(self.__class__, "__unittest_skip__", False) or | ||
| 571 | - getattr(testMethod, "__unittest_skip__", False)): | ||
| 572 | - # If the class or method was skipped. | ||
| 573 | - try: | ||
| 570 | + try: | ||
| 571 | + testMethod = getattr(self, self._testMethodName) | ||
| 572 | + if (getattr(self.__class__, "__unittest_skip__", False) or | ||
| 573 | + getattr(testMethod, "__unittest_skip__", False)): | ||
| 574 | + # If the class or method was skipped. | ||
| 574 | 575 | skip_why = (getattr(self.__class__, '__unittest_skip_why__', '') | |
| 575 | 576 | or getattr(testMethod, '__unittest_skip_why__', '')) | |
| 576 | 577 | self._addSkip(result, self, skip_why) | |
| 577 | - finally: | ||
| 578 | - result.stopTest(self) | ||
| 579 | - return | ||
| 580 | - expecting_failure_method = getattr(testMethod, | ||
| 581 | - "__unittest_expecting_failure__", False) | ||
| 582 | - expecting_failure_class = getattr(self, | ||
| 583 | - "__unittest_expecting_failure__", False) | ||
| 584 | - expecting_failure = expecting_failure_class or expecting_failure_method | ||
| 585 | - outcome = _Outcome(result) | ||
| 586 | - try: | ||
| 587 | - self._outcome = outcome | ||
| 578 | + return | ||
| 579 | + | ||
| 580 | + expecting_failure = ( | ||
| 581 | + getattr(self, "__unittest_expecting_failure__", False) or | ||
| 582 | + getattr(testMethod, "__unittest_expecting_failure__", False) | ||
| 583 | + ) | ||
| 584 | + outcome = _Outcome(result) | ||
| 585 | + try: | ||
| 586 | + self._outcome = outcome | ||
| 588 | 587 | ||
| 589 | - with outcome.testPartExecutor(self): | ||
| 590 | - self._callSetUp() | ||
| 591 | - if outcome.success: | ||
| 592 | - outcome.expecting_failure = expecting_failure | ||
| 593 | - with outcome.testPartExecutor(self, isTest=True): | ||
| 594 | - self._callTestMethod(testMethod) | ||
| 595 | - outcome.expecting_failure = False | ||
| 596 | 588 | with outcome.testPartExecutor(self): | |
| 597 | - self._callTearDown() | ||
| 598 | - | ||
| 599 | - self.doCleanups() | ||
| 600 | - for test, reason in outcome.skipped: | ||
| 601 | - self._addSkip(result, test, reason) | ||
| 602 | - self._feedErrorsToResult(result, outcome.errors) | ||
| 603 | - if outcome.success: | ||
| 604 | - if expecting_failure: | ||
| 605 | - if outcome.expectedFailure: | ||
| 606 | - self._addExpectedFailure(result, outcome.expectedFailure) | ||
| 589 | + self._callSetUp() | ||
| 590 | + if outcome.success: | ||
| 591 | + outcome.expecting_failure = expecting_failure | ||
| 592 | + with outcome.testPartExecutor(self, isTest=True): | ||
| 593 | + self._callTestMethod(testMethod) | ||
| 594 | + outcome.expecting_failure = False | ||
| 595 | + with outcome.testPartExecutor(self): | ||
| 596 | + self._callTearDown() | ||
| 597 | + | ||
| 598 | + self.doCleanups() | ||
| 599 | + for test, reason in outcome.skipped: | ||
| 600 | + self._addSkip(result, test, reason) | ||
| 601 | + self._feedErrorsToResult(result, outcome.errors) | ||
| 602 | + if outcome.success: | ||
| 603 | + if expecting_failure: | ||
| 604 | + if outcome.expectedFailure: | ||
| 605 | + self._addExpectedFailure(result, outcome.expectedFailure) | ||
| 606 | + else: | ||
| 607 | + self._addUnexpectedSuccess(result) | ||
| 607 | 608 | else: | |
| 608 | - self._addUnexpectedSuccess(result) | ||
| 609 | - else: | ||
| 610 | - result.addSuccess(self) | ||
| 611 | - return result | ||
| 609 | + result.addSuccess(self) | ||
| 610 | + return result | ||
| 611 | + finally: | ||
| 612 | + # explicitly break reference cycles: | ||
| 613 | + # outcome.errors -> frame -> outcome -> outcome.errors | ||
| 614 | + # outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure | ||
| 615 | + outcome.errors.clear() | ||
| 616 | + outcome.expectedFailure = None | ||
| 617 | + | ||
| 618 | + # clear the outcome, no more needed | ||
| 619 | + self._outcome = None | ||
| 620 | + | ||
| 612 | 621 | finally: | |
| 613 | 622 | result.stopTest(self) | |
| 614 | - if orig_result is None: | ||
| 615 | - stopTestRun = getattr(result, 'stopTestRun', None) | ||
| 616 | - if stopTestRun is not None: | ||
| 617 | - stopTestRun() | ||
| 618 | - | ||
| 619 | - # explicitly break reference cycles: | ||
| 620 | - # outcome.errors -> frame -> outcome -> outcome.errors | ||
| 621 | - # outcome.expectedFailure -> frame -> outcome -> outcome.expectedFailure | ||
| 622 | - outcome.errors.clear() | ||
| 623 | - outcome.expectedFailure = None | ||
| 624 | - | ||
| 625 | - # clear the outcome, no more needed | ||
| 626 | - self._outcome = None | ||
| 623 | + if stopTestRun is not None: | ||
| 624 | + stopTestRun() | ||
| 627 | 625 | ||
| 628 | 626 | def doCleanups(self): | |
| 629 | 627 | """Execute all cleanup functions. Normally called for you after | |
| Back | FazBrowse Home | New Git URL |
0 commit comments