Skip to content

Commit fa624e1

Browse files
Merge branch 'main' into traceback-to-handle-error-msgs-with-period
2 parents d859b9f + 349de57 commit fa624e1

File tree

8 files changed

+40
-6
lines changed

8 files changed

+40
-6
lines changed

Doc/library/argparse.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ by setting ``color`` to ``False``::
638638
... help='an integer for the accumulator')
639639
>>> parser.parse_args(['--help'])
640640

641+
Note that when ``color=True``, colored output depends on both environment
642+
variables and terminal capabilities. However, if ``color=False``, colored
643+
output is always disabled, even if environment variables like ``FORCE_COLOR``
644+
are set.
645+
641646
.. versionadded:: 3.14
642647

643648

Lib/annotationlib.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,11 @@ def evaluate(
187187
except Exception:
188188
if not is_forwardref_format:
189189
raise
190+
191+
# All variables, in scoping order, should be checked before
192+
# triggering __missing__ to create a _Stringifier.
190193
new_locals = _StringifierDict(
191-
{**builtins.__dict__, **locals},
194+
{**builtins.__dict__, **globals, **locals},
192195
globals=globals,
193196
owner=owner,
194197
is_class=self.__forward_is_class__,

Lib/mailbox.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,8 +2090,6 @@ def closed(self):
20902090
return False
20912091
return self._file.closed
20922092

2093-
__class_getitem__ = classmethod(GenericAlias)
2094-
20952093

20962094
class _PartialFile(_ProxyFile):
20972095
"""A read-only wrapper of part of a file."""

Lib/pdb.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3603,7 +3603,6 @@ def main():
36033603
invalid_args = list(itertools.takewhile(lambda a: a.startswith('-'), args))
36043604
if invalid_args:
36053605
parser.error(f"unrecognized arguments: {' '.join(invalid_args)}")
3606-
sys.exit(2)
36073606

36083607
if opts.module:
36093608
file = opts.module

Lib/test/test_annotationlib.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,32 @@ def test_name_lookup_without_eval(self):
18771877

18781878
self.assertEqual(exc.exception.name, "doesntexist")
18791879

1880+
def test_evaluate_undefined_generic(self):
1881+
# Test the codepath where have to eval() with undefined variables.
1882+
class C:
1883+
x: alias[int, undef]
1884+
1885+
generic = get_annotations(C, format=Format.FORWARDREF)["x"].evaluate(
1886+
format=Format.FORWARDREF,
1887+
globals={"alias": dict}
1888+
)
1889+
self.assertNotIsInstance(generic, ForwardRef)
1890+
self.assertIs(generic.__origin__, dict)
1891+
self.assertEqual(len(generic.__args__), 2)
1892+
self.assertIs(generic.__args__[0], int)
1893+
self.assertIsInstance(generic.__args__[1], ForwardRef)
1894+
1895+
generic = get_annotations(C, format=Format.FORWARDREF)["x"].evaluate(
1896+
format=Format.FORWARDREF,
1897+
globals={"alias": Union},
1898+
locals={"alias": dict}
1899+
)
1900+
self.assertNotIsInstance(generic, ForwardRef)
1901+
self.assertIs(generic.__origin__, dict)
1902+
self.assertEqual(len(generic.__args__), 2)
1903+
self.assertIs(generic.__args__[0], int)
1904+
self.assertIsInstance(generic.__args__[1], ForwardRef)
1905+
18801906
def test_fwdref_invalid_syntax(self):
18811907
fr = ForwardRef("if")
18821908
with self.assertRaises(SyntaxError):

Lib/test/test_genericalias.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from functools import partial, partialmethod, cached_property
1818
from graphlib import TopologicalSorter
1919
from logging import LoggerAdapter, StreamHandler
20-
from mailbox import Mailbox, _PartialFile
20+
from mailbox import Mailbox
2121
try:
2222
import ctypes
2323
except ImportError:
@@ -117,7 +117,7 @@ class BaseTest(unittest.TestCase):
117117
Iterable, Iterator,
118118
Reversible,
119119
Container, Collection,
120-
Mailbox, _PartialFile,
120+
Mailbox,
121121
ContextVar, Token,
122122
Field,
123123
Set, MutableSet,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix partial evaluation of :class:`annotationlib.ForwardRef` objects which rely
2+
on names defined as globals.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The internal class ``mailbox._ProxyFile`` is no longer a parameterized generic.

0 commit comments

Comments
 (0)