python/cpython
View on GitHub ↗ ★ 77,791 Python
The Python programming language
548 mentions on Hacker News by 400 people: 44 stories, 504 comments · first 2014-12-30 · latest 2026-10-27
20082026
-
The central dispatch of the VM is a good place to start: https://github.com/python/cpython/blob/main/Python/ceval.c#L...
comment by formerly_proven · 2021-10-06 · in Python 3.11: “Zero cost” exception handling -
…The Zip format is truly awful. https://en.wikipedia.org/wiki/ZIP_(file_format)#Central_dire... https://github.com/python/cpython/blob/7e465a6b8273dc0b6cb48...
comment by jfrunyon · 2021-09-19 · in Reality Check for Cloudflare Wasm Workers and Rust -
From the python source code: https://github.com/python/cpython/blob/11749e2dc20ad6a76e9a3... It seems to be shelling out to osascript, either telling it to OpenURL or open.
comment by zirak · 2021-08-16 · in Antigravity.py (2020) -
…uses a black-box model to explain it rather than looking at the source, `iadd` uses `extend`: https://github.com/python/cpython/blob/main/Objects/listobje...
comment by ndr · 2021-08-13 · in The difference between a=a+b and a+=b in Python -
…Python implementations that get used if the _operator C module is not available for some reason): https://github.com/python/cpython/blob/3.9/Modules/_operator...
comment by JonathonW · 2021-08-08 · in The unknown features of Python's `operator` module -
`methodcaller` ( https://github.com/python/cpython/blob/6a6bcf16370beff2e0d1a... ) is just syntax sugar around `getattr` + a function call which is just syntax sugar + default implementation of `__getattr__` which is basically exactly what…
comment by icegreentea2 · 2021-08-08 · in The unknown features of Python's `operator` module -
…below, you might as well just be using a def, which is exactly what is done in the operator module: https://github.com/python/cpython/blob/3.9/Lib/operator.py#L... For someone familiar with the operator module, there is a final small…
comment by randallsquared · 2021-08-08 · in The unknown features of Python's `operator` module -
The operator module is very old: https://github.com/python/cpython/blob/ea4d3f0804a3aad5afaa6... PEP8 was introduced in 2001: https://www.python.org/dev/peps/pep-0008/
comment by O5vYtytb · 2021-08-08 · in The unknown features of Python's `operator` module -
…does just create a bunch of different Python objects and then use type() to extract their types: https://github.com/python/cpython/blob/v3.9.6/Lib/types.py Some examples from that file: async def _ag(): yield _ag = _ag() AsyncGeneratorType…
comment by simonw · 2021-07-24 · in How the Python import system works -
…3.6 is much more readable than 3.9 so I recommend reading that if you want to see how it works. https://github.com/python/cpython/blob/3.6/Lib/collections/_...
comment by Spivak · 2021-07-21 · in Namedtuple in a Post-Dataclasses World -
See CPython's https://github.com/python/cpython/blob/main/Objects/listsort... for details about the sort. In fact, its "galloping" was inspired by a paper of which Demaine was a co-author (reference in the file already linked to).…
comment by tim-peters · 2021-07-13 · in Beating TimSort at Merging -
Wow. Thanks for writing it. I believe this is the part you are referring to: https://github.com/python/cpython/blob/main/Objects/listobje...
comment by adamgordonbell · 2021-07-13 · in Beating TimSort at Merging -
…be as fast as this implementation? edit: Okay one reason is that heapq.merge is written in python: https://github.com/python/cpython/blob/6252670732c68420c2a8b... It might also be since the python version has more options (like arbitrarily…
comment by CogitoCogito · 2021-07-13 · in Beating TimSort at Merging -
…I'd recommend taking at least a quick look at any python standard library module before using it. https://github.com/python/cpython/tree/main/Lib
comment by vajrabum · 2021-06-30 · in Learn by reading code: Python standard library design decisions explained -
This is the complete code (from here: https://github.com/python/cpython/blob/3.9/Lib/statistics.py ) if iter(data) is data: data = list(data) n = len(data) if n < 1: raise StatisticsError('mean requires at least one data point') T, total,…
comment by mattkrause · 2021-06-30 · in Learn by reading code: Python standard library design decisions explained -
…of strings, so I added an extra layer of caching, but it looks like it's not needed anymore. [1]: https://github.com/python/cpython/blob/3.10/Objects/unicodeo...
comment by ciupicri · 2021-06-13 · in Reducing Python String Memory Use in Apache Arrow 0.12 (2019) -
…>>> data = (1_000_000_000.1, 1.1) * 50_000 >>> statistics.fmean(data) 500000000.6 Implementation at https://github.com/python/cpython/blob/6df926f1c46eb6db7b5dc... .
comment by eesmith · 2021-06-11 · in How to average floating point numbers (2015) -
…_sum function for example, which you can see maps _exact_ratio over the data before summing: https://github.com/python/cpython/blob/3.9/Lib/statistics.py...
comment by _delirium · 2021-06-11 · in How to average floating point numbers (2015) -
…may be slower, but I am hoping that it is easy understand why they ought to be preferred. [1]: https://github.com/python/cpython/blob/5571cabf1b3385087aba2... [2]: https://www.nu42.com/2015/03/how-you-average-numbers.html
comment by nanis · 2021-06-09 · in Perl Data Language: Scientific Computing with Perl -
This has been brought up: https://github.com/python/cpython/pull/26264#discussion_r640... Though personally I would dislike this, since every time somebody mentioned about type hints they commented on the property of them not causing 'ANY…
comment by treesciencebot · 2021-06-02 · in Making CPython Faster -
…Code-ish?[2] Probably not! [1] https://github.com/AdoptOpenJDK/openjdk-jdk11u/blob/master/s... [2] https://github.com/python/cpython/blob/main/Objects/listobje...
comment by throwaway2037 · 2021-05-27 · in It's probably time to stop recommending Clean Code (2020) -
…the last month and a few more in flight. I.e the project has already started. See for example https://github.com/python/cpython/pull/25152
comment by kzrdude · 2021-05-13 · in Faster CPython Ideas – Issue Tracker for Faster CPython Project -
Why isn't this hosted at https://github.com/python/cpython/issues ?
comment by etskinner · 2021-05-13 · in Faster CPython Ideas – Issue Tracker for Faster CPython Project -
This project has already submitted a few small changes into cpython, like https://github.com/python/cpython/pull/25069 and https://github.com/python/cpython/pull/25729
comment by kzrdude · 2021-05-13 · in Faster CPython Ideas – Issue Tracker for Faster CPython Project -
…notes (alongside an explicit statement that it would become default four years later in 3.10): https://github.com/python/cpython/blob/a41782cc84bcd813209a0...
comment by williamsmj · 2021-04-16 · in PEP 563, PEP 649 and the future of pydantic and FastAPI -
…and it's already no small feat to have added them without breaking backwards compatibility. [0] https://github.com/python/cpython/blob/8a232c7b17a2e41ae14d8...
comment by guitarbill · 2021-04-16 · in PEP 563, PEP 649 and the future of pydantic and FastAPI -
…cannot assign to literal [0]: https://docs.python.org/3/library/stdtypes.html#float.fromhe... [1]: https://github.com/python/cpython/blob/5ce227f3a767e6e44e7c4... [2]: https://github.com/python/cpython/blob/5ce227f3a767e6e44e7c4...
comment by css · 2021-04-13 · in In Python, `[0xfor x in (1, 2, 3)]` returns `[15]` -
…It doesn't, since 3.8. It tries fcopyfile() and only if it fails, does the read/write dance. See: https://github.com/python/cpython/blob/master/Lib/shutil.py#...
comment by vetinari · 2021-04-08 · in Surprisingly Slow -
https://github.com/python/cpython/blob/master/Objects/dictob...
comment by knome · 2021-03-26 · in How to implement a hash table in C -
…an attribute that begins with assert Or any of the names in this surprising hardcoded list of typos https://github.com/python/cpython/blob/fdb9efce6ac211f973088...
comment by progval · 2021-03-25 · in My Python testing style guide (2017) -
…Python 3.x being slower than 2.x. [0] https://rubykaigi.org/2016/presentations/tanaka_akr.html [1] https://github.com/python/cpython/blob/8d21aa21f2cbc6d50aab3... [2] https://github.com/python/cpython/blob/39f643614d03748a5fad4...
comment by pansa2 · 2021-03-24 · in Donald Knuth’s Algorithm D, its implementation in Hacker’s Delight and elsewhere -
…pass Here is the C version (with a comment a little way down describing the "fast path advantages": https://github.com/python/cpython/blob/93d33b47af70ede473f82...
comment by benhoyt · 2021-03-15 · in Performance comparison: counting words in Python, Go, C++, C, Awk, Forth, Rust -
…Counter.update instead because I thought linking to the call site is clearer), but here it is: https://github.com/python/cpython/blob/2fe408497e6838b6fb761... Again, very straightforward, based on dict. Python itself does not function at…
comment by oefrha · 2021-03-15 · in Performance comparison: counting words in Python, Go, C++, C, Awk, Forth, Rust -
…amount of) overhead. Now, dict is optimized, but that's a builtin type. You don't need PSL. https://github.com/python/cpython/blob/2fe408497e6838b6fb761...
comment by oefrha · 2021-03-15 · in Performance comparison: counting words in Python, Go, C++, C, Awk, Forth, Rust -
…as a performance optimization. Type-specific free lists (just a few examples; there are more): * https://github.com/python/cpython/blob/master/Objects/floato... * https://github.com/python/cpython/blob/master/Objects/tupleo... And also…
comment by loeg · 2021-03-13 · in Speed of Rust vs. C -
Thank you for the pointer. Seems they have already fixed it. https://github.com/python/cpython/pull/24721/files
comment by kamyarg · 2021-03-03 · in Python 3.10.0a6 is available, now with 100% more pattern matching -
There's a "Show Source" link in the navigation that points to https://github.com/python/cpython/blob/master/Doc/whatsnew/3...
comment by ktpsns · 2021-03-03 · in Python 3.10.0a6 is available, now with 100% more pattern matching -
It's not that powerful, if I'm reading it correctly: https://github.com/python/cpython/commit/34df10a9a16b38d5442... The sprintf is to a temporary buffer that's converted to a PyUnicode object before returning, so subsequent portions of…
comment by duckerude · 2021-02-19 · in Python 3.x: RCE in Python applications that accept floats as untrusted input -
…repr'd, an sprintf call with a statically sized buffer of 256 bytes is used to produce a string: https://github.com/python/cpython/commit/d9b8f138b7df3b455b54653ca59f491b4840d6fa#diff-4e23b3237d0aa08bf4c434d75fab19200a80837bd147051fefccd98b…
comment by dividuum · 2021-02-18 · in Python 3.x: RCE in Python applications that accept floats as untrusted input -
For reference, here is the live copy of longobject.c: https://github.com/python/cpython/blob/master/Objects/longob... Python 2 had distinct `int` and `long` types, but Python 3 merged them together into just `int`. I wasn't sure if the…
comment by nayuki · 2021-02-15 · in Python Internals Serie: Int (Long) Object -
https://github.com/python/cpython/commit/b71c7dc9ddd6997be49... commit b71c7dc9ddd6997be49ed6aaabf99a067e2c0388 Author: Victor Stinner <victor.stinner@gmail.com> Date: Fri Oct 10 11:55:41 2014 +0200 Issue #22591: Drop support of MS-DOS…
comment by eesmith · 2021-01-24 · in Pip has dropped support for Python 2 -
…treated as a format string _if_ there are arguments. If not, it is treated as a literal string: https://github.com/python/cpython/blob/dcea78ff53d02733ac598...
comment by dagenix · 2021-01-21 · in Python 3's F-Strings: An Improved String Formatting Syntax -
PyCon totally does affect python.tar.gz. https://github.com/python/cpython/pulls?q=+label%3Asprint (and that link doesn’t capture the PEPs hashed out among other things.) Also, why the hell make a new account for each comment?
comment by oefrha · 2020-12-31 · in PyPy Project looking for sponsorship to add support for Apple Silicon -
…for macOS 11 and Apple Silicon count? Here's a list of Apple-submitted PRs on python/cpython: https://github.com/python/cpython/pulls?q=is%3Apr+author%3Al... Also some co-authored patches excluded by the search. See…
comment by oefrha · 2020-12-31 · in PyPy Project looking for sponsorship to add support for Apple Silicon -
…is part of the standard library, and was part of the standard library in 3.0, and contained reduce: https://github.com/python/cpython/blob/3.0/Lib/functools.py#... What he meant to say is that it's removed from the list of builtins.
comment by geofft · 2020-12-25 · in In CPython, types implemented in C are part of the type tree -
Python's developers must have enormous heads if that's the case: https://github.com/python/cpython/blob/b8fde8b5418b75d2935d0...
comment by brobinson · 2020-12-21 · in Write code. Not too much. Mostly functions. -
There are fast-paths for these cases, like this one: https://github.com/python/cpython/blob/4b8cdfcb22fbeaab9d954... (and note the comment above it about integer addition!) But the cpython folk make understandability an explicit goal of…
comment by ketralnis · 2020-12-11 · in How the Python object system works -
Thanks. So it seems both were updated with 'key' at the same time: https://github.com/python/cpython/commit/871934d4cf00687b3d1... Now I'm wondering - what is the point of the python version, if it will always be overridden by the C…
comment by rahimnathwani · 2020-11-23 · in Using Python's Bisect Module -
…is in Modules/_bisectmodule.c, whereas the Python version is in Lib/bisect.py. Python version: https://github.com/python/cpython/blob/master/Lib/bisect.py C version: https://github.com/python/cpython/blob/master/Modules/_bisec...
comment by kaunta · 2020-11-22 · in Using Python's Bisect Module -
https://github.com/python/cpython/blob/master/Lib/bisect.py
comment by rahimnathwani · 2020-11-22 · in Using Python's Bisect Module