diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md new file mode 120000 index 00000000000000..be77ac83a1895c --- /dev/null +++ b/.claude/CLAUDE.md @@ -0,0 +1 @@ +../AGENTS.md \ No newline at end of file diff --git a/.gitignore b/.gitignore index e53548f1fd45a0..00813f9d1b6b00 100644 --- a/.gitignore +++ b/.gitignore @@ -178,8 +178,12 @@ Python/frozen_modules/MANIFEST /python !/Python/ -# People's custom https://docs.anthropic.com/en/docs/claude-code/memory configs. -/.claude/ +# Local AI agent scratch state (per-PR and per-branch notebooks, sandbox +# experiments) and personal agent overrides, none of which are committed. +/.claude/pr-* +/.claude/branch-* +/.claude/sandbox/ +AGENTS.local.md CLAUDE.local.md #### main branch only stuff below this line, things to backport go above. #### diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000000000..d23d0c9315d3f3 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,16 @@ +# AI agent guidance + +CPython has a [policy on the use of AI tools](https://devguide.python.org/getting-started/ai-tools/). +All use of AI tools and agents when working on or interacting with CPython +must follow it. + +> [!important] +> **Primary directive**: Read the policy before making or proposing any changes. + +When acting on this repository, apply the policy's core principles: + +- Consider whether the change is necessary. +- Make minimal, focused changes. +- Follow existing coding style and patterns. +- Write tests that exercise the change. +- Keep backwards compatibility with prior releases in mind. diff --git a/Lib/idlelib/editor.py b/Lib/idlelib/editor.py index a040d791bdeb52..89e1725e15f30b 100644 --- a/Lib/idlelib/editor.py +++ b/Lib/idlelib/editor.py @@ -1175,12 +1175,7 @@ def load_extension(self, name): if keydefs: self.apply_bindings(keydefs) for vevent in keydefs: - methodname = vevent.replace("-", "_") - while methodname[:1] == '<': - methodname = methodname[1:] - while methodname[-1:] == '>': - methodname = methodname[:-1] - methodname = methodname + "_event" + methodname = vevent.strip("<>").replace("-", "_") + "_event" if hasattr(ins, methodname): self.text.bind(vevent, getattr(ins, methodname)) diff --git a/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst new file mode 100644 index 00000000000000..056b54fd12aeda --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-31-09-01-22.gh-issue-156439.j9WHCc.rst @@ -0,0 +1,3 @@ +:func:`socket.if_nametoindex` and :func:`socket.if_indextoname` are now +available on platforms that provide them but not +``if_nameindex``, such as Android before API level 24. diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index f89b91b9b99753..dd5a906dda1a38 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -2181,7 +2181,7 @@ _socket_if_nameindex(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) */ -#if (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) +#if (defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)) PyDoc_STRVAR(_socket_if_nametoindex__doc__, "if_nametoindex($module, oname, /)\n" @@ -2213,9 +2213,9 @@ _socket_if_nametoindex(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) */ +#endif /* (defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS)) */ -#if (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) +#if (defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)) PyDoc_STRVAR(_socket_if_indextoname__doc__, "if_indextoname($module, if_index, /)\n" @@ -2244,7 +2244,7 @@ _socket_if_indextoname(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS)) */ +#endif /* (defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS)) */ #if defined(CMSG_LEN) @@ -2478,4 +2478,4 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) #ifndef _SOCKET_CMSG_SPACE_METHODDEF #define _SOCKET_CMSG_SPACE_METHODDEF #endif /* !defined(_SOCKET_CMSG_SPACE_METHODDEF) */ -/*[clinic end generated code: output=acc30d6fdeb54e90 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=aa9082b592c39fa5 input=a9049054013a1b77]*/ diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 70d3738b176cda..82899572f80255 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -631,14 +631,14 @@ _PyLong_##NAME##_Converter(PyObject *obj, void *ptr) \ return 1; \ } -#if defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) +#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) # ifdef MS_WINDOWS UNSIGNED_INT_CONVERTER(NetIfindex, NET_IFINDEX) # else # define _PyLong_NetIfindex_Converter _PyLong_UnsignedInt_Converter # define NET_IFINDEX unsigned int # endif -#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) +#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) /*[python input] class NET_IFINDEX_converter(CConverter): @@ -7403,6 +7403,9 @@ _socket_if_nameindex_impl(PyObject *module) #endif } +#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) + +#if defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS) /*[clinic input] _socket.if_nametoindex @@ -7432,6 +7435,9 @@ _socket_if_nametoindex_impl(PyObject *module, PyObject *oname) return PyLong_FromUnsignedLong(index); } +#endif // defined(HAVE_IF_NAMETOINDEX) || defined(MS_WINDOWS) + +#if defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) /*[clinic input] @permit_long_summary @@ -7456,7 +7462,7 @@ _socket_if_indextoname_impl(PyObject *module, NET_IFINDEX index) return PyUnicode_DecodeFSDefault(name); } -#endif // defined(HAVE_IF_NAMEINDEX) || defined(MS_WINDOWS) +#endif // defined(HAVE_IF_INDEXTONAME) || defined(MS_WINDOWS) #ifdef CMSG_LEN diff --git a/configure b/configure index a2ca40de07d54e..7e4844263a3491 100755 --- a/configure +++ b/configure @@ -20804,12 +20804,24 @@ if test "x$ac_cv_func_grantpt" = xyes then : printf "%s\n" "#define HAVE_GRANTPT 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "if_indextoname" "ac_cv_func_if_indextoname" +if test "x$ac_cv_func_if_indextoname" = xyes +then : + printf "%s\n" "#define HAVE_IF_INDEXTONAME 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "if_nameindex" "ac_cv_func_if_nameindex" if test "x$ac_cv_func_if_nameindex" = xyes then : printf "%s\n" "#define HAVE_IF_NAMEINDEX 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "if_nametoindex" "ac_cv_func_if_nametoindex" +if test "x$ac_cv_func_if_nametoindex" = xyes +then : + printf "%s\n" "#define HAVE_IF_NAMETOINDEX 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "initgroups" "ac_cv_func_initgroups" if test "x$ac_cv_func_initgroups" = xyes diff --git a/configure.ac b/configure.ac index e1333230fefa68..8345c97349b738 100644 --- a/configure.ac +++ b/configure.ac @@ -5528,7 +5528,8 @@ AC_CHECK_FUNCS([ \ getgrnam_r getgrouplist gethostname getitimer getloadavg getlogin getlogin_r \ getpeername getpgid getpid getppid getpriority _getpty \ getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \ - getspnam gettid getuid getwd grantpt if_nameindex initgroups kill killpg lchown linkat \ + getspnam gettid getuid getwd grantpt if_indextoname if_nameindex \ + if_nametoindex initgroups kill killpg lchown linkat \ lockf lstat lutimes madvise mbrtowc memrchr mkdirat mkfifo mkfifoat \ mknod mknodat mktime mmap mremap nice openat opendir pathconf pause \ pidfd_open pidfd_getfd pidfd_send_signal pipe \ diff --git a/pyconfig.h.in b/pyconfig.h.in index c2a36afe334763..e798a061ab6d09 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -751,9 +751,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_ICONV_H +/* Define to 1 if you have the 'if_indextoname' function. */ +#undef HAVE_IF_INDEXTONAME + /* Define to 1 if you have the 'if_nameindex' function. */ #undef HAVE_IF_NAMEINDEX +/* Define to 1 if you have the 'if_nametoindex' function. */ +#undef HAVE_IF_NAMETOINDEX + /* Define if you have the 'inet_aton' function. */ #undef HAVE_INET_ATON