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
1 change: 0 additions & 1 deletion Doc/data/stable_abi.dat
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ PyType_GetFlags
PyType_GetModule
PyType_GetModuleState
PyType_GetSlot
PyType_HasFeature
PyType_IsSubtype
PyType_Modified
PyType_Ready
Expand Down
2 changes: 1 addition & 1 deletion Doc/howto/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ roughly equivalent to:
.. testcode::

class MethodType:
"Emulate Py_MethodType in Objects/classobject.c"
"Emulate PyMethod_Type in Objects/classobject.c"

def __init__(self, func, obj):
self.__func__ = func
Expand Down
8 changes: 4 additions & 4 deletions Include/methodobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ PyAPI_FUNC(PyObject *) PyCMethod_New(PyMethodDef *, PyObject *,

#define METH_COEXIST 0x0040

#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000
#define METH_FASTCALL 0x0080
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030a0000
# define METH_FASTCALL 0x0080
#endif

/* This bit is preserved for Stackless Python */
#ifdef STACKLESS
#define METH_STACKLESS 0x0100
# define METH_STACKLESS 0x0100
#else
#define METH_STACKLESS 0x0000
# define METH_STACKLESS 0x0000
#endif

/* METH_METHOD means the function stores an
Expand Down
3 changes: 2 additions & 1 deletion Lib/compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ def main():
# if flist is provided then load it
if args.flist:
try:
with (sys.stdin if args.flist=='-' else open(args.flist)) as f:
with (sys.stdin if args.flist=='-' else
open(args.flist, encoding="utf-8")) as f:
for line in f:
compile_dests.append(line.strip())
except OSError:
Expand Down
9 changes: 6 additions & 3 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,11 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None,
argval, argrepr = _get_const_info(arg, constants)
elif op in hasname:
argval, argrepr = _get_name_info(arg, names)
elif op in hasjabs:
argval = arg*2
argrepr = "to " + repr(argval)
elif op in hasjrel:
argval = offset + 2 + arg
argval = offset + 2 + arg*2
argrepr = "to " + repr(argval)
elif op in haslocal:
argval, argrepr = _get_name_info(arg, varnames)
Expand Down Expand Up @@ -437,9 +440,9 @@ def findlabels(code):
for offset, op, arg in _unpack_opargs(code):
if arg is not None:
if op in hasjrel:
label = offset + 2 + arg
label = offset + 2 + arg*2
elif op in hasjabs:
label = arg
label = arg*2
else:
continue
if label not in labels:
Expand Down
1 change: 1 addition & 0 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.10a2 3432 (Function annotation for MAKE_FUNCTION is changed from dict to tuple bpo-42202)
# Python 3.10a2 3433 (RERAISE restores f_lasti if oparg != 0)
# Python 3.10a6 3434 (PEP 634: Structural Pattern Matching)
# Python 3.10a7 3435 Use instruction offsets (as opposed to byte offsets).

#
# MAGIC must change whenever the bytecode emitted by the compiler may no
Expand Down
2 changes: 1 addition & 1 deletion Lib/lib2to3/pgen2/pgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ParserGenerator(object):
def __init__(self, filename, stream=None):
close_stream = None
if stream is None:
stream = open(filename)
stream = open(filename, encoding="utf-8")
close_stream = stream.close
self.filename = filename
self.stream = stream
Expand Down
2 changes: 1 addition & 1 deletion Lib/multiprocessing/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def _close_stdin():
try:
fd = os.open(os.devnull, os.O_RDONLY)
try:
sys.stdin = open(fd, closefd=False)
sys.stdin = open(fd, encoding="utf-8", closefd=False)
except:
os.close(fd)
raise
Expand Down
2 changes: 1 addition & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ def main():
print("The program finished and will be restarted")
except Restart:
print("Restarting", mainpyfile, "with arguments:")
print("\t" + " ".join(args))
print("\t" + " ".join(sys.argv[1:]))
except SystemExit:
# In most cases SystemExit does not warrant a post-mortem session.
print("The program exited via sys.exit(). Exit status:", end=' ')
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def _captured_script(script):
indented = script.replace('\n', '\n ')
wrapped = dedent(f"""
import contextlib
with open({w}, 'w') as spipe:
with open({w}, 'w', encoding="utf-8") as spipe:
with contextlib.redirect_stdout(spipe):
{indented}
""")
return wrapped, open(r)
return wrapped, open(r, encoding="utf-8")


def _run_output(interp, request, shared=None):
Expand All @@ -45,7 +45,7 @@ def _running(interp):
def run():
interpreters.run_string(interp, dedent(f"""
# wait for "signal"
with open({r}) as rpipe:
with open({r}, encoding="utf-8") as rpipe:
rpipe.read()
"""))

Expand All @@ -54,7 +54,7 @@ def run():

yield

with open(w, 'w') as spipe:
with open(w, 'w', encoding="utf-8") as spipe:
spipe.write('done')
t.join()

Expand Down Expand Up @@ -806,7 +806,7 @@ def f():
@unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
def test_fork(self):
import tempfile
with tempfile.NamedTemporaryFile('w+') as file:
with tempfile.NamedTemporaryFile('w+', encoding="utf-8") as file:
file.write('')
file.flush()

Expand All @@ -816,7 +816,7 @@ def test_fork(self):
try:
os.fork()
except RuntimeError:
with open('{file.name}', 'w') as out:
with open('{file.name}', 'w', encoding='utf-8') as out:
out.write('{expected}')
""")
interpreters.run_string(self.id, script)
Expand Down
14 changes: 8 additions & 6 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def tearDown(self):

def create_readonly_file(self, filename):
file_path = os.path.join(self.temp_dir, filename)
with open(file_path, 'w') as file:
with open(file_path, 'w', encoding="utf-8") as file:
file.write(filename)
os.chmod(file_path, stat.S_IREAD)

Expand Down Expand Up @@ -1468,7 +1468,7 @@ def setUp(self):
('invalid', '@no-such-path\n'),
]
for path, text in file_texts:
with open(path, 'w') as file:
with open(path, 'w', encoding="utf-8") as file:
file.write(text)

parser_signature = Sig(fromfile_prefix_chars='@')
Expand Down Expand Up @@ -1498,7 +1498,7 @@ def setUp(self):
('hello', 'hello world!\n'),
]
for path, text in file_texts:
with open(path, 'w') as file:
with open(path, 'w', encoding="utf-8") as file:
file.write(text)

class FromFileConverterArgumentParser(ErrorRaisingArgumentParser):
Expand Down Expand Up @@ -1580,7 +1580,8 @@ class TestFileTypeR(TempDirMixin, ParserTestCase):
def setUp(self):
super(TestFileTypeR, self).setUp()
for file_name in ['foo', 'bar']:
with open(os.path.join(self.temp_dir, file_name), 'w') as file:
with open(os.path.join(self.temp_dir, file_name),
'w', encoding="utf-8") as file:
file.write(file_name)
self.create_readonly_file('readonly')

Expand All @@ -1601,7 +1602,7 @@ class TestFileTypeDefaults(TempDirMixin, ParserTestCase):
"""Test that a file is not created unless the default is needed"""
def setUp(self):
super(TestFileTypeDefaults, self).setUp()
file = open(os.path.join(self.temp_dir, 'good'), 'w')
file = open(os.path.join(self.temp_dir, 'good'), 'w', encoding="utf-8")
file.write('good')
file.close()

Expand All @@ -1620,7 +1621,8 @@ class TestFileTypeRB(TempDirMixin, ParserTestCase):
def setUp(self):
super(TestFileTypeRB, self).setUp()
for file_name in ['foo', 'bar']:
with open(os.path.join(self.temp_dir, file_name), 'w') as file:
with open(os.path.join(self.temp_dir, file_name),
'w', encoding="utf-8") as file:
file.write(file_name)

argument_signatures = [
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_baseexception.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def test_inheritance(self):
except TypeError:
pass

inheritance_tree = open(os.path.join(os.path.split(__file__)[0],
'exception_hierarchy.txt'))
inheritance_tree = open(
os.path.join(os.path.split(__file__)[0], 'exception_hierarchy.txt'),
encoding="utf-8")
try:
superclass_name = inheritance_tree.readline().rstrip()
try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def create_modules(modules):
try:
for m in modules:
fname = m + '.py'
with open(fname, 'w') as f:
with open(fname, 'w', encoding="utf-8") as f:
f.write(textwrap.dedent(modules[m]))
linecache.checkcache(fname)
importlib.invalidate_caches()
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def test_boolean(self):

def test_fileclosed(self):
try:
with open(os_helper.TESTFN, "w") as f:
with open(os_helper.TESTFN, "w", encoding="utf-8") as f:
self.assertIs(f.closed, False)
self.assertIs(f.closed, True)
finally:
Expand Down
14 changes: 8 additions & 6 deletions Lib/test/test_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ def test_oct(self):

def write_testfile(self):
# NB the first 4 lines are also used to test input, below
fp = open(TESTFN, 'w')
fp = open(TESTFN, 'w', encoding="utf-8")
self.addCleanup(unlink, TESTFN)
with fp:
fp.write('1+1\n')
Expand All @@ -1171,7 +1171,7 @@ def write_testfile(self):

def test_open(self):
self.write_testfile()
fp = open(TESTFN, 'r')
fp = open(TESTFN, encoding="utf-8")
with fp:
self.assertEqual(fp.readline(4), '1+1\n')
self.assertEqual(fp.readline(), 'The quick brown fox jumps over the lazy dog.\n')
Expand All @@ -1197,15 +1197,17 @@ def test_open_default_encoding(self):

self.write_testfile()
current_locale_encoding = locale.getpreferredencoding(False)
fp = open(TESTFN, 'w')
with warnings.catch_warnings():
warnings.simplefilter("ignore", EncodingWarning)
fp = open(TESTFN, 'w')
with fp:
self.assertEqual(fp.encoding, current_locale_encoding)
finally:
os.environ.clear()
os.environ.update(old_environ)

def test_open_non_inheritable(self):
fileobj = open(__file__)
fileobj = open(__file__, encoding="utf-8")
with fileobj:
self.assertFalse(os.get_inheritable(fileobj.fileno()))

Expand Down Expand Up @@ -1300,7 +1302,7 @@ def test_pow(self):

def test_input(self):
self.write_testfile()
fp = open(TESTFN, 'r')
fp = open(TESTFN, encoding="utf-8")
savestdin = sys.stdin
savestdout = sys.stdout # Eats the echo
try:
Expand Down Expand Up @@ -2022,7 +2024,7 @@ def _run_child(self, child, terminal_input):
os.write(fd, terminal_input)

# Get results from the pipe
with open(r, "r") as rpipe:
with open(r, encoding="utf-8") as rpipe:
lines = []
while True:
line = rpipe.readline().strip()
Expand Down
13 changes: 6 additions & 7 deletions Lib/test/test_compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def setUp(self):
self.directory = tempfile.mkdtemp()
self.source_path = os.path.join(self.directory, '_test.py')
self.bc_path = importlib.util.cache_from_source(self.source_path)
with open(self.source_path, 'w') as file:
with open(self.source_path, 'w', encoding="utf-8") as file:
file.write('x = 123\n')
self.source_path2 = os.path.join(self.directory, '_test2.py')
self.bc_path2 = importlib.util.cache_from_source(self.source_path2)
Expand All @@ -73,7 +73,7 @@ def tearDown(self):

def add_bad_source_file(self):
self.bad_source_path = os.path.join(self.directory, '_test_bad.py')
with open(self.bad_source_path, 'w') as file:
with open(self.bad_source_path, 'w', encoding="utf-8") as file:
file.write('x (\n')

def timestamp_metadata(self):
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_no_pycache_in_non_package(self):
data_file = os.path.join(data_dir, 'file')
os.mkdir(data_dir)
# touch data/file
with open(data_file, 'w'):
with open(data_file, 'wb'):
pass
compileall.compile_file(data_file)
self.assertFalse(os.path.exists(os.path.join(data_dir, '__pycache__')))
Expand Down Expand Up @@ -440,8 +440,7 @@ def setUpClass(cls):
if not directory.is_dir():
directory.mkdir()
directory_created = True
with path.open('w') as file:
file.write('# for test_compileall')
path.write_text('# for test_compileall', encoding="utf-8")
except OSError:
sys_path_writable = False
break
Expand Down Expand Up @@ -704,7 +703,7 @@ def test_include_file_with_arg(self):
f2 = script_helper.make_script(self.pkgdir, 'f2', '')
f3 = script_helper.make_script(self.pkgdir, 'f3', '')
f4 = script_helper.make_script(self.pkgdir, 'f4', '')
with open(os.path.join(self.directory, 'l1'), 'w') as l1:
with open(os.path.join(self.directory, 'l1'), 'w', encoding="utf-8") as l1:
l1.write(os.path.join(self.pkgdir, 'f1.py')+os.linesep)
l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
self.assertRunOK('-i', os.path.join(self.directory, 'l1'), f4)
Expand All @@ -718,7 +717,7 @@ def test_include_file_no_arg(self):
f2 = script_helper.make_script(self.pkgdir, 'f2', '')
f3 = script_helper.make_script(self.pkgdir, 'f3', '')
f4 = script_helper.make_script(self.pkgdir, 'f4', '')
with open(os.path.join(self.directory, 'l1'), 'w') as l1:
with open(os.path.join(self.directory, 'l1'), 'w', encoding="utf-8") as l1:
l1.write(os.path.join(self.pkgdir, 'f2.py')+os.linesep)
self.assertRunOK('-i', os.path.join(self.directory, 'l1'))
self.assertNotCompiled(f1)
Expand Down
Loading