Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/_pyrepl/_module_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def __init__(self, namespace: Mapping[str, Any] | None = None) -> None:
self._global_cache: list[pkgutil.ModuleInfo] = []
self._curr_sys_path: list[str] = sys.path[:]

def get_completions(self, line: str) -> list[str]:
def get_completions(self, line: str) -> list[str] | None:
"""Return the next possible import completions for 'line'."""
result = ImportParser(line).parse()
if not result:
return []
return None
try:
return self.complete(*result)
except Exception:
Expand Down
5 changes: 3 additions & 2 deletions Lib/_pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def get_stem(self) -> str:
return "".join(b[p + 1 : self.pos])

def get_completions(self, stem: str) -> list[str]:
if module_completions := self.get_module_completions():
module_completions = self.get_module_completions()
if module_completions is not None:
return module_completions
if len(stem) == 0 and self.more_lines is not None:
b = self.buffer
Expand Down Expand Up @@ -165,7 +166,7 @@ def get_completions(self, stem: str) -> list[str]:
result.sort()
return result

def get_module_completions(self) -> list[str]:
def get_module_completions(self) -> list[str] | None:
line = self.get_line()
return self.config.module_completer.get_completions(line)

Expand Down
2 changes: 2 additions & 0 deletions Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,8 @@ def _get_ptext_to_endchars(value, endchars):
a flag that is True iff there were any quoted printables decoded.

"""
if not value:
return '', '', False
fragment, *remainder = _wsp_splitter(value, 1)
vchars = []
escape = False
Expand Down
33 changes: 33 additions & 0 deletions Lib/test/test_email/test__header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,19 @@ def test_get_qp_ctext_non_printables(self):
[errors.NonPrintableDefect], ')')
self.assertEqual(ptext.defects[0].non_printables[0], '\x00')

def test_get_qp_ctext_close_paren_only(self):
self._test_get_x(parser.get_qp_ctext,
')', '', ' ', [], ')')

def test_get_qp_ctext_open_paren_only(self):
self._test_get_x(parser.get_qp_ctext,
'(', '', ' ', [], '(')

def test_get_qp_ctext_no_end_char(self):
self._test_get_x(parser.get_qp_ctext,
'', '', ' ', [], '')


# get_qcontent

def test_get_qcontent_only(self):
Expand Down Expand Up @@ -503,6 +516,14 @@ def test_get_qcontent_non_printables(self):
[errors.NonPrintableDefect], '"')
self.assertEqual(ptext.defects[0].non_printables[0], '\x00')

def test_get_qcontent_empty(self):
self._test_get_x(parser.get_qcontent,
'"', '', '', [], '"')

def test_get_qcontent_no_end_char(self):
self._test_get_x(parser.get_qcontent,
'', '', '', [], '')

# get_atext

def test_get_atext_only(self):
Expand Down Expand Up @@ -1283,6 +1304,18 @@ def test_get_dtext_open_bracket_mid_word(self):
self._test_get_x(parser.get_dtext,
'foo[bar', 'foo', 'foo', [], '[bar')

def test_get_dtext_open_bracket_only(self):
self._test_get_x(parser.get_dtext,
'[', '', '', [], '[')

def test_get_dtext_close_bracket_only(self):
self._test_get_x(parser.get_dtext,
']', '', '', [], ']')

def test_get_dtext_empty(self):
self._test_get_x(parser.get_dtext,
'', '', '', [], '')

# get_domain_literal

def test_get_domain_literal_only(self):
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,12 @@ def testLdexp(self):
self.assertEqual(math.ldexp(NINF, n), NINF)
self.assertTrue(math.isnan(math.ldexp(NAN, n)))

@requires_IEEE_754
def testLdexp_denormal(self):
# Denormal output incorrectly rounded (truncated)
# on some Windows.
self.assertEqual(math.ldexp(6993274598585239, -1126), 1e-323)

def testLog(self):
self.assertRaises(TypeError, math.log)
self.assertRaises(TypeError, math.log, 1, 2, 3)
Expand Down
28 changes: 20 additions & 8 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,14 @@ def test_func(self):

class TestPyReplModuleCompleter(TestCase):
def setUp(self):
import importlib
# Make iter_modules() search only the standard library.
# This makes the test more reliable in case there are
# other user packages/scripts on PYTHONPATH which can
# interfere with the completions.
lib_path = os.path.dirname(importlib.__path__[0])
self._saved_sys_path = sys.path
sys.path = [lib_path]

def tearDown(self):
sys.path = self._saved_sys_path
Expand All @@ -932,14 +939,6 @@ def prepare_reader(self, events, namespace):
return reader

def test_import_completions(self):
import importlib
# Make iter_modules() search only the standard library.
# This makes the test more reliable in case there are
# other user packages/scripts on PYTHONPATH which can
# intefere with the completions.
lib_path = os.path.dirname(importlib.__path__[0])
sys.path = [lib_path]

cases = (
("import path\t\n", "import pathlib"),
("import importlib.\t\tres\t\n", "import importlib.resources"),
Expand Down Expand Up @@ -1052,6 +1051,19 @@ def test_invalid_identifiers(self):
output = reader.readline()
self.assertEqual(output, expected)

def test_no_fallback_on_regular_completion(self):
cases = (
("import pri\t\n", "import pri"),
("from pri\t\n", "from pri"),
("from typing import Na\t\n", "from typing import Na"),
)
for code, expected in cases:
with self.subTest(code=code):
events = code_to_events(code)
reader = self.prepare_reader(events, namespace={})
output = reader.readline()
self.assertEqual(output, expected)

def test_get_path_and_prefix(self):
cases = (
('', ('', '')),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
When auto-completing an import in the :term:`REPL`, finding no candidates
now issues no suggestion, rather than suggestions from the current namespace.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
``ldexp()`` on Windows doesn't round subnormal results before Windows 11,
but should. Python's :func:`math.ldexp` wrapper now does round them, so
results may change slightly, in rare cases of very small results, on
Windows versions before 11.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed :exc:`UnboundLocalError` that could occur during :mod:`email` header
parsing if an expected trailing delimiter is missing in some contexts.
21 changes: 21 additions & 0 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,27 @@ math_ldexp_impl(PyObject *module, double x, PyObject *i)
} else {
errno = 0;
r = ldexp(x, (int)exp);
#ifdef _MSC_VER
if (DBL_MIN > r && r > -DBL_MIN) {
/* Denormal (or zero) results can be incorrectly rounded here (rather,
truncated). Fixed in newer versions of the C runtime, included
with Windows 11. */
int original_exp;
frexp(x, &original_exp);
if (original_exp > DBL_MIN_EXP) {
/* Shift down to the smallest normal binade. No bits lost. */
int shift = DBL_MIN_EXP - original_exp;
x = ldexp(x, shift);
exp -= shift;
}
/* Multiplying by 2**exp finishes the job, and the HW will round as
appropriate. Note: if exp < -DBL_MANT_DIG, all of x is shifted
to be < 0.5ULP of smallest denorm, so should be thrown away. If
exp is so very negative that ldexp underflows to 0, that's fine;
no need to check in advance. */
r = x*ldexp(1.0, (int)exp);
}
#endif
if (isinf(r))
errno = ERANGE;
}
Expand Down
Loading