Skip to content

[pull] main from RustPython:main #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 4, 2025
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
370 changes: 213 additions & 157 deletions Lib/configparser.py

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions Lib/genericpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import stat

__all__ = ['commonprefix', 'exists', 'getatime', 'getctime', 'getmtime',
'getsize', 'isdir', 'isfile', 'islink', 'samefile', 'sameopenfile',
'samestat']
'getsize', 'isdevdrive', 'isdir', 'isfile', 'isjunction', 'islink',
'lexists', 'samefile', 'sameopenfile', 'samestat', 'ALLOW_MISSING']


# Does a path exist?
Expand All @@ -22,6 +22,15 @@ def exists(path):
return True


# Being true for dangling symbolic links is also useful.
def lexists(path):
"""Test whether a path exists. Returns True for broken symbolic links"""
try:
os.lstat(path)
except (OSError, ValueError):
return False
return True

# This follows symbolic links, so both islink() and isdir() can be true
# for the same path on systems that support symlinks
def isfile(path):
Expand Down Expand Up @@ -57,6 +66,21 @@ def islink(path):
return stat.S_ISLNK(st.st_mode)


# Is a path a junction?
def isjunction(path):
"""Test whether a path is a junction
Junctions are not supported on the current platform"""
os.fspath(path)
return False


def isdevdrive(path):
"""Determines whether the specified path is on a Windows Dev Drive.
Dev Drives are not supported on the current platform"""
os.fspath(path)
return False


def getsize(filename):
"""Return the size of a file, reported by os.stat()."""
return os.stat(filename).st_size
Expand Down Expand Up @@ -165,3 +189,12 @@ def _check_arg_types(funcname, *args):
f'os.PathLike object, not {s.__class__.__name__!r}') from None
if hasstr and hasbytes:
raise TypeError("Can't mix strings and bytes in path components") from None

# A singleton with a true boolean value.
@object.__new__
class ALLOW_MISSING:
"""Special value for use in realpath()."""
def __repr__(self):
return 'os.path.ALLOW_MISSING'
def __reduce__(self):
return self.__class__.__name__
25 changes: 22 additions & 3 deletions Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
# find this format documented anywhere.


import operator
import os
import re
import sys
Expand Down Expand Up @@ -166,14 +167,28 @@ def _parse(tokens, priority=-1):

def _as_int(n):
try:
i = round(n)
round(n)
except TypeError:
raise TypeError('Plural value must be an integer, got %s' %
(n.__class__.__name__,)) from None
return _as_int2(n)

def _as_int2(n):
try:
return operator.index(n)
except TypeError:
pass

import warnings
frame = sys._getframe(1)
stacklevel = 2
while frame.f_back is not None and frame.f_globals.get('__name__') == __name__:
stacklevel += 1
frame = frame.f_back
warnings.warn('Plural value must be an integer, got %s' %
(n.__class__.__name__,),
DeprecationWarning, 4)
DeprecationWarning,
stacklevel)
return n


Expand All @@ -200,7 +215,7 @@ def c2py(plural):
elif c == ')':
depth -= 1

ns = {'_as_int': _as_int}
ns = {'_as_int': _as_int, '__name__': __name__}
exec('''if True:
def func(n):
if not isinstance(n, int):
Expand Down Expand Up @@ -280,6 +295,7 @@ def gettext(self, message):
def ngettext(self, msgid1, msgid2, n):
if self._fallback:
return self._fallback.ngettext(msgid1, msgid2, n)
n = _as_int2(n)
if n == 1:
return msgid1
else:
Expand All @@ -293,6 +309,7 @@ def pgettext(self, context, message):
def npgettext(self, context, msgid1, msgid2, n):
if self._fallback:
return self._fallback.npgettext(context, msgid1, msgid2, n)
n = _as_int2(n)
if n == 1:
return msgid1
else:
Expand Down Expand Up @@ -579,6 +596,7 @@ def dngettext(domain, msgid1, msgid2, n):
try:
t = translation(domain, _localedirs.get(domain, None))
except OSError:
n = _as_int2(n)
if n == 1:
return msgid1
else:
Expand All @@ -598,6 +616,7 @@ def dnpgettext(domain, context, msgid1, msgid2, n):
try:
t = translation(domain, _localedirs.get(domain, None))
except OSError:
n = _as_int2(n)
if n == 1:
return msgid1
else:
Expand Down
Loading