Update some libs and tests to `3.14.7` by ShaharNaveh · Pull Request #8559 · RustPython/RustPython · GitHub
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
13 changes: 7 additions & 6 deletions Lib/_pydatetime.py
2 changes: 1 addition & 1 deletion Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,7 @@ def truncate(self, pos=None):
"""Truncate size to pos, where pos is an int."""
self._unsupported("truncate")

def readline(self):
def readline(self, size=-1, /):
"""Read until newline or EOF.

Returns an empty string if EOF is hit immediately.
Expand Down
3 changes: 3 additions & 0 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,9 @@ def _prog_name(prog=None):
if modspec is None:
# simple script
return _os.path.basename(arg0)
if modspec.name != '__main__' and arg0 != modspec.origin:
# named module executed as main without altering sys.argv[0]
return _os.path.basename(arg0)
py = _os.path.basename(_sys.executable)
if modspec.name != '__main__':
# imported module or package
Expand Down
6 changes: 3 additions & 3 deletions Lib/base64.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Base16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data encodings"""
"""Base16, Base32, Base64 (RFC 4648), Base85 and Ascii85 data encodings"""

# Modified 04-Oct-1995 by Jack Jansen to use binascii module
# Modified 30-Dec-2003 by Barry Warsaw to add full RFC 3548 support
Expand Down Expand Up @@ -147,7 +147,7 @@ def urlsafe_b64decode(s):
characters present in the input.
'''
_B32_DECODE_MAP01_DOCSTRING = '''
RFC 3548 allows for optional mapping of the digit 0 (zero) to the
RFC 4648 allows for optional mapping of the digit 0 (zero) to the
letter O (oh), and for optional mapping of the digit 1 (one) to
either the letter I (eye) or letter L (el). The optional argument
map01 when not None, specifies which letter the digit 1 should be
Expand Down Expand Up @@ -261,7 +261,7 @@ def b32hexdecode(s, casefold=False):
extra_args='')


# RFC 3548, Base 16 Alphabet specifies uppercase, but hexlify() returns
# RFC 4648, Base 16 Alphabet specifies uppercase, but hexlify() returns
# lowercase. The RFC also recommends against accepting input case
# insensitively.
def b16encode(s):
Expand Down
3 changes: 3 additions & 0 deletions Lib/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,9 @@ class Counter(dict):
or multiset. Elements are stored as dictionary keys and their counts
are stored as dictionary values.

When constructed from a Mapping or Counter, the original object's
values will be used as the initial counts.

>>> c = Counter('abcdeabcdabcaba') # count elements from a string

>>> c.most_common(3) # three most common elements
Expand Down
4 changes: 3 additions & 1 deletion Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,9 @@ def _write_section(self, fp, section_name, section_items, delimiter, unnamed=Fal
value = self._interpolation.before_write(self, section_name, key,
value)
if value is not None or not self._allow_no_value:
value = delimiter + str(value).replace('\n', '\n\t')
# Convert all possible line-endings into '\n\t'
value = (delimiter + str(value).replace('\r\n', '\n')
.replace('\r', '\n').replace('\n', '\n\t'))
else:
value = ""
fp.write("{}{}\n".format(key, value))
Expand Down
48 changes: 31 additions & 17 deletions Lib/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,14 @@ def __init__(self):
def sniff(self, sample, delimiters=None):
"""
Returns a dialect (or None) corresponding to the sample

If several delimiters fit the sample equally well, the
delimiters listed in the preferred attribute are preferred, in
that order, no matter how many times each of them occurs.
"""

sample = sample.replace('\r\n', '\n').replace('\r', '\n')

quotechar, doublequote, delimiter, skipinitialspace = \
self._guess_quote_and_delimiter(sample, delimiters)
if not delimiter:
Expand Down Expand Up @@ -282,12 +288,16 @@ def _guess_quote_and_delimiter(self, data, delimiters):
"""
import re

# The body of a quoted field ends at the first quote which is
# not doubled, as it does for a reader. A lazy ".*?" scans to
# the end of the sample instead, from every start: quadratically.
body = r'(?:(?P=quote){2}|(?!(?P=quote)).)*+'
matches = []
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?P=delim)', # ,".*?",
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # ".*?",
r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\']).*?(?P=quote)(?:$|\n)', # ,".*?"
r'(?:^|\n)(?P<quote>["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space)
regexp = re.compile(restr, re.DOTALL | re.MULTILINE)
for restr in (r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\'])%s(?P=quote)(?P=delim)', # ,"...",
r'(?:^|\n)(?P<quote>["\'])%s(?P=quote)(?P<delim>[^\w\n"\'])(?P<space> ?)', # "...",
r'(?P<delim>[^\w\n"\'])(?P<space> ?)(?P<quote>["\'])%s(?P=quote)(?:$|\n)', # ,"..."
r'(?:^|\n)(?P<quote>["\'])%s(?P=quote)(?:$|\n)'): # "..." (no delim, no space)
regexp = re.compile(restr % body, re.DOTALL | re.MULTILINE)
matches = regexp.findall(data)
if matches:
break
Expand Down Expand Up @@ -330,18 +340,22 @@ def _guess_quote_and_delimiter(self, data, delimiters):
delim = ''
skipinitialspace = 0

# if we see an extra quote between delimiters, we've got a
# double quoted format
dq_regexp = re.compile(
r"((%(delim)s)|^)\W*%(quote)s[^%(delim)s\n]*%(quote)s[^%(delim)s\n]*%(quote)s\W*((%(delim)s)|$)" % \
{'delim':re.escape(delim), 'quote':quotechar}, re.MULTILINE)



if dq_regexp.search(data):
doublequote = True
else:
doublequote = False
# A doubled quote character inside a quoted field means
# a double quoted format. Match whole fields, so that a match
# cannot slide across field boundaries.
doublequote = False
if delim:
dq_regexp = re.compile(
r"(?:(?<=%(delim)s)|^)%(space)s%(quote)s" # ,"
r"((?:%(quote)s%(quote)s|[^%(quote)s]++)*+)" # the body
r"%(quote)s(?:%(delim)s|$)" # ",
% {'delim': re.escape(delim), 'quote': quotechar,
# Skipping spaces after a space rescans them.
'space': ' *+' if delim != ' ' else ''},
re.MULTILINE)
dquotechar = quotechar * 2
doublequote = any(dquotechar in m[1]
for m in dq_regexp.finditer(data))

return (quotechar, doublequote, delim, skipinitialspace)

Expand Down
1 change: 1 addition & 0 deletions Lib/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,7 @@ def _process_class(cls, init, repr, eq, order, unsafe_hash, frozen,
# classes with slots. These could be slightly more performant if we generated
# the code instead of iterating over fields. But that can be a project for
# another day, if performance becomes an issue.

def _dataclass_getstate(self):
return [getattr(self, f.name) for f in fields(self)]

Expand Down
2 changes: 2 additions & 0 deletions Lib/difflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,8 @@ def make_table(self,fromlines,tolines,fromdesc='',todesc='',context=False,

# change tabs to spaces before it gets more difficult after we insert
# markup
# it also removes trailing newlines, causing some diffs to be missed
# see: gh-71896
fromlines,tolines = self._tab_newline_replace(fromlines,tolines)

# create diffs iterator which generates side by side from/to data
Expand Down
8 changes: 4 additions & 4 deletions Lib/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def glob(pathname, *, root_dir=None, dir_fd=None, recursive=False,
If `dir_fd` is not None, it should be a file descriptor referring to a
directory, and paths will then be relative to that directory.

If `include_hidden` is true, the patterns '*', '?', '**' will match
hidden directories.
If `include_hidden` is true, wildcards can match path segments beginning
with a dot ('.').

If `recursive` is true, the pattern '**' will match any files and
zero or more directories and subdirectories.
Expand Down Expand Up @@ -64,8 +64,8 @@ def iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False,
If `dir_fd` is not None, it should be a file descriptor referring to a
directory, and paths will then be relative to that directory.

If `include_hidden` is true, the patterns '*', '?', '**' will match
hidden directories.
If `include_hidden` is true, wildcards can match path segments beginning
with a dot ('.').

If `recursive` is true, the pattern '**' will match any files and
zero or more directories and subdirectories.
Expand Down
29 changes: 19 additions & 10 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,18 @@ def ispackage(object):
def ismethoddescriptor(object):
"""Return true if the object is a method descriptor.

But not if ismethod() or isclass() or isfunction() are true.
But not if ismethod(), isclass() or isfunction() is true.

This is new in Python 2.2, and, for example, is true of int.__add__.
An object passing this test has a __get__ attribute, but not a
__set__ attribute or a __delete__ attribute. Beyond that, the set
of attributes varies; __name__ is usually sensible, and __doc__
often is.
An object passing this test (for example, int.__add__) has a __get__
attribute, but not a __set__ attribute or a __delete__ attribute.
Beyond that, the set of attributes varies; __name__ is usually
sensible, and __doc__ often is.

Methods implemented via descriptors that also pass one of the other
tests return false from the ismethoddescriptor() test, simply because
the other tests promise more -- you can, e.g., count on having the
__func__ attribute (etc) when an object passes ismethod()."""
tests (ismethod(), isclass(), isfunction()) make this function return
false, simply because those other tests promise more -- you can, for
example, count on having the __func__ attribute when an object passes
ismethod()."""
if isclass(object) or ismethod(object) or isfunction(object):
# mutual exclusion
return False
Expand All @@ -219,8 +219,13 @@ def ismethoddescriptor(object):
def isdatadescriptor(object):
"""Return true if the object is a data descriptor.

But not if ismethod(), isclass() or isfunction() is true.

Data descriptors have a __set__ or a __delete__ attribute. Examples are
properties (defined in Python) and getsets and members (defined in C).
properties, getsets, and members. For the latter two (defined only in C
extension modules) more specific tests are available as well:
isgetsetdescriptor() and ismemberdescriptor(), respectively.

Typically, data descriptors will also have __name__ and __doc__ attributes
(properties, getsets, and members have both of these attributes), but this
is not guaranteed."""
Expand Down Expand Up @@ -2712,6 +2717,10 @@ def __init__(self, name, kind, *, default=_empty, annotation=_empty):
raise ValueError(msg)
self._kind = _POSITIONAL_ONLY
name = 'implicit{}'.format(name[1:])
elif name == '.format':
# gh-151665: Hidden parameter of compiler-generated annotation and type
# alias/typevar evaluators. Show it as "format".
name = 'format'

# It's possible for C functions to have a positional-only parameter
# where the name is a keyword, so for compatibility we'll allow it.
Expand Down
2 changes: 1 addition & 1 deletion Lib/json/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def py_scanstring(s, end, strict=True,
if strict:
#msg = "Invalid control character %r at" % (terminator,)
msg = "Invalid control character {0!r} at".format(terminator)
raise JSONDecodeError(msg, s, end)
raise JSONDecodeError(msg, s, end - 1)
else:
_append(terminator)
continue
Expand Down
6 changes: 0 additions & 6 deletions Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,12 +545,6 @@ def getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')):

"""

import warnings
warnings._deprecated(
"locale.getdefaultlocale",
"{name!r} is deprecated and slated for removal in Python {remove}. "
"Use setlocale(), getencoding() and getlocale() instead.",
remove=(3, 15))
return _getdefaultlocale(envvars)


Expand Down
4 changes: 2 additions & 2 deletions Lib/mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def read(self, filename, strict=True):
list of standard types, else to the list of non-standard
types.
"""
with open(filename, encoding='utf-8') as fp:
with open(filename, encoding='utf-8', errors='surrogateescape') as fp:
self.readfp(fp, strict)

def readfp(self, fp, strict=True):
Expand Down Expand Up @@ -435,7 +435,7 @@ def init(files=None):

def read_mime_types(file):
try:
f = open(file, encoding='utf-8')
f = open(file, encoding='utf-8', errors='surrogateescape')
except OSError:
return None
with f:
Expand Down
2 changes: 1 addition & 1 deletion Lib/ntpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def _isreservedname(name):
def expanduser(path):
"""Expand ~ and ~user constructs.

If user or $HOME is unknown, do nothing."""
If user or home directory is unknown, do nothing."""
path = os.fspath(path)
if isinstance(path, bytes):
seps = b'\\/'
Expand Down
4 changes: 3 additions & 1 deletion Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,7 @@ class Helper:
'async': ('async', ''),
'await': ('await', ''),
'break': ('break', 'while for'),
'case': 'match',
'class': ('class', 'CLASSES SPECIALMETHODS'),
'continue': ('continue', 'while for'),
'def': ('function', ''),
Expand All @@ -1887,11 +1888,12 @@ class Helper:
'for': ('for', 'break continue while'),
'from': 'import',
'global': ('global', 'nonlocal NAMESPACES'),
'if': ('if', 'TRUTHVALUE'),
'if': ('if', 'TRUTHVALUE match'),
'import': ('import', 'MODULES'),
'in': ('in', 'SEQUENCEMETHODS'),
'is': 'COMPARISON',
'lambda': ('lambda', 'FUNCTIONS'),
'match': ('match', 'if'),
'nonlocal': ('nonlocal', 'global NAMESPACES'),
'not': 'BOOLEAN',
'or': 'BOOLEAN',
Expand Down
3 changes: 2 additions & 1 deletion Lib/pydoc_data/module_docs.py
Loading
Loading