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
-
…Proposal to use PEG parser in python https://www.python.org/dev/peps/pep-0617/ Python PEG grammar https://github.com/python/cpython/blob/3.9/Grammar/python.gr...
comment by coderzach · 2020-11-15 · in Packrat Parsing: Simple, Powerful, Lazy, Linear Time [pdf] -
…of its hash table implementation that it has been optimized over and over decades now. [1]: https://github.com/python/cpython/blob/master/Objects/dictob... [2]: https://github.com/redis/redis/blob/unstable/src/dict.c
comment by woadwarrior01 · 2020-11-15 · in Pydis – Redis clone in 250 lines of Python, for performance comparison -
…and it'll yield values (not hard to do with a recursive one, I just didn't feel like it): https://github.com/python/cpython/blob/2.7/Lib/contextlib.py... Seems like the __new__/__init__ issues exist with ExitStack as well, unlike with…
comment by Groxx · 2020-11-10 · in On the Beauty of Python's ExitStack (2015) -
…[2]: https://repl.it/@Groxx/TepidRosybrownLocatorprogram#main.py [3]: https://github.com/python/cpython/blob/master/Lib/contextlib...
comment by Groxx · 2020-11-10 · in On the Beauty of Python's ExitStack (2015) -
In fact, that's exactly how Python implements UNARY_NEGATIVE: https://github.com/python/cpython/blob/v3.9.0/Python/ceval.c... If you look a bit further down in the original article, you'll see that the BINARY_ADD instruction does something…
comment by teraflop · 2020-11-09 · in How Python bytecode is executed -
Direct threading is in here https://github.com/python/cpython/blob/0564aafb71a153dd0aca4...
comment by jashmatthews · 2020-10-28 · in Pyston v2: Faster Python -
…based interpreter it was 20 years ago. no threading, no super instructions, no jitting, nothing. https://github.com/python/cpython/blob/master/Python/ceval.c...
comment by toolslive · 2020-10-28 · in Pyston v2: Faster Python -
…unless you supply your own timer, and time.perf_counter does measure wall clock time. See https://github.com/python/cpython/blob/ec42789e6e14f6b6ac135... https://docs.python.org/3/library/time.html#time.perf_counte...
comment by oefrha · 2020-10-20 · in PyInstrument – A statistical Python profile that focuses on the slow parts -
…for release in December. Details available here: https://pybind11.readthedocs.io/en/latest and https://github.com/python/cpython/pull/22670 .
comment by wjakob · 2020-10-20 · in Python 3.9 -
…'b']) where the namedtuple function actually has to hack around the fact that it's not a macro : https://github.com/python/cpython/blob/644e94272a89196801825... tldr: Foo needs to have __module__ = 'yourmodule' __qualname__ =…
comment by uryga · 2020-10-15 · in PEP 638 – Syntactic Macros -
…with a finite maxsize. Implementation-wise it's identical to using maxsize=None. See source: https://github.com/python/cpython/blob/3.9/Lib/functools.py#...
comment by uyt · 2020-10-05 · in Python 3.9 -
…including CPython, use computed gotos for a not insignificant performance improvement. https://github.com/python/cpython/blob/master/Python/ceval.c...
comment by Jasper_ · 2020-09-24 · in How the CPython compiler works -
…can be found in ceval.c. There is a big switch case for each python bytecode opcode starting at https://github.com/python/cpython/blob/master/Python/ceval.c... One can see even the simplest operations call quite a lot of stuff. I gave up…
comment by xaedes · 2020-09-24 · in How the CPython compiler works -
…as I can tell functools.partial has been implemented in C since it was added sixteen years ago ( https://github.com/python/cpython/commit/9c323f8de4910dfc0ba... . ), and it's faster than lambda ( https://gist.github.com/wrmsr/1e13eda3ed7828…
comment by BiteCode_dev · 2020-09-07 · in Fastcore: A library that extends Python with new features -
…as I can tell functools.partial has been implemented in C since it was added sixteen years ago ( https://github.com/python/cpython/commit/9c323f8de4910dfc0ba... ), and it's faster than lambda ( https://gist.github.com/wrmsr/1e13eda3ed782886…
comment by wrmsr · 2020-09-05 · in Fastcore: A library that extends Python with new features -
In case anyone is curious, sets were dicts in the original implementation: https://github.com/python/cpython/blob/a690a9967e715663b7a42... It was changed in 2005 for python 2.5 https://github.com/python/cpython/commit/9f1a6796eb83a2884df...
comment by viraptor · 2020-08-23 · in Python Hash Tables: understanding dictionaries -
…digging through history, it looks like the change in behavior for byte strings was intentional: https://github.com/python/cpython/commit/6ccd3f2dbcb98b33a71... Author: Guido van Rossum <guido@python.org> Date: Tue Oct 9 03:46:30 2007 +0000…
comment by price · 2020-08-17 · in In the Turkish locale, "INFO".lower() != "info" -
…of real-life VMs. Even VMs which do interpret don’t do the way written in the article, take a look: https://github.com/python/cpython/blob/v3.9.0rc1/Python/ceva... What exactly it is you’re learning then?
comment by Const-me · 2020-08-15 · in Write Your Own Virtual Machine -
…or IO bound tasks in Python, for example when reading from a socket the GIL gets released at https://github.com/python/cpython/blob/e822e37946f27c09953bb...
comment by Znafon · 2020-08-14 · in Django Async: What's new and what's next? -
…return. The C tuple packing function cannot return directly from the Python function. Looking at https://github.com/python/cpython/blob/master/Python/ceval.c , here is the code that needs to be executed after the tuple is constructed: case…
comment by tom_mellior · 2020-07-22 · in Data structures and algorithms I actually used while working at tech companies -
…does not mean adding pipes and arguments. This is one important benefit of not using shell. See https://github.com/python/cpython/blob/master/Lib/webbrowser...
comment by Too · 2020-07-14 · in Hacking with environment variables -
…and nowadays, it almost is. This is the only part left that uses it, to create the constructor: https://github.com/python/cpython/blob/master/Lib/collection... Even there it's not strictly necessary. You could accomplish the same thing…
comment by duckerude · 2020-07-06 · in Brython – A Python 3 implementation for client-side web programming -
…as the first operation, not knowing whether it received an iterator or some other kind of iterable. https://github.com/python/cpython/blob/384621c42f9102e31ba2c... If you search for `list` in the CPython code, you'll find many examples of…
comment by xapata · 2020-06-25 · in Specific ways to write better Python (2017) -
If you want to follow along in the Python source code, the relevant file is https://github.com/python/cpython/blob/master/Python/ceval.c . The interpreter is a loop over a big switch statement on the byte codes. Most operations are pretty…
comment by tom_mellior · 2020-06-24 · in The PVM – Python Virtual Machine -
…[2], so aren't such a special case anymore. [1] https://www.python.org/dev/peps/pep-0530/ [2] https://github.com/python/cpython/pull/20370 , https://github.com/python/cpython/pull/20370/files
comment by mkl · 2020-06-24 · in PEP 622 – Structural Pattern Matching -
…of the Python project, called distutils.dist.Distribution which has a function named is_pure(): https://github.com/python/cpython/blob/e42b705188271da108de4... Which makes sure that it doesn't have any known external modules or c…
comment by X-Istence · 2020-06-21 · in Python Wheels Crosses 90% -
…[2]: https://www.programminglogic.com/example-of-client-server-pr... [3]: https://github.com/python/cpython/blob/3.8/Lib/asyncio/unix_...
comment by ben509 · 2020-06-14 · in Async Python is not faster -
…which is ~1500 LOC [2]. I guess parsing CSVs reliably is a reasonably difficult undertaking. [1] https://github.com/python/cpython/blob/3.8/Lib/csv.py [2] https://github.com/python/cpython/blob/4a21e57fe55076c77b0ee...
comment by asadjb · 2020-05-15 · in So you want to write your own CSV code (2014) -
One obvious use case invoked all the time: tracebacks are generated through introspection. https://github.com/python/cpython/blob/3.8/Lib/traceback.py
comment by oefrha · 2020-05-05 · in Python goto implemented with system trace function (2017) -
…). It is Turing complete. See source code and documentation at https://github.com/python/cpython/blob/master/Lib/pickle.py#... https://github.com/python/cpython/blob/master/Lib/pickletool... N.B: "Turing complete" really
comment by bugmen0t · 2020-04-24 · in Accidentally Turing-Complete -
As far as I can see this should be the list of changes: https://github.com/python/cpython/blob/v2.7.18/Misc/NEWS.d/2...
comment by wichert · 2020-04-21 · in Python 2.7.18, the last release of Python 2 -
If you're interested in what actually changed in this update, the release notes are here: https://github.com/python/cpython/blob/2.7/Misc/NEWS.d/2.7.1...
comment by csande17 · 2020-04-20 · in Python 2.7.18, the last release of Python 2 -
They stopped making changes on January 1st 2020 https://github.com/python/cpython/commits/2.7 This is the release of the changes up to that date, since they don't release instantly.
comment by shpx · 2020-04-20 · in Python 2.7.18, the last release of Python 2 -
…implemented in this way. A concrete example would be Python's PyObject which share PyObject_HEAD. https://github.com/python/cpython/blob/master/Include/object...
comment by epr · 2020-04-15 · in Tell HN: C Experts Panel – Ask us anything about C -
…earlier comment I was responding to mentioned only Python, not Go. And Python suppresses SIGPIPE: https://github.com/python/cpython/blob/master/Python/pylifec... , https://github.com/python/cpython/blob/master/Doc/library/si... > Does the…
comment by loeg · 2020-03-22 · in How do Unix pipes work? -
This was definitely not accidental. Here is the commit that introduces `all` and `any`: https://github.com/python/cpython/commit/96229b19181 It includes a test for the empty case: `self.assertEqual(all([]), True)`. They knew what they were…
comment by globular-toast · 2020-03-18 · in The 2,500 year old history of why Python’s all([]) returns True -
…definition. def all(iterable): for element in iterable: if not element: return False return True https://github.com/python/cpython/blob/master/Python/bltinmo...
comment by syphilis2 · 2020-03-18 · in The 2,500 year old history of why Python’s all([]) returns True -
eval(/exec) is how dataclasses (and namedtuples before them) work: https://github.com/python/cpython/blob/4c1b6a6f4fc46add0097e... . It is a big gun, but sometimes (usually deep within lib code) big guns are the right answer. Don't use…
comment by wrmsr · 2020-02-17 · in Overload functions in Python -
I _think_ this may be the implementation: https://github.com/python/cpython/blob/60ac6ed5579f6666130fc... There are copious notes in there about the implementation and it indicates linked lists are used. EDIT: Blargh, it's here:…
comment by Rapzid · 2020-02-08 · in Python dicts are now ordered -
Don't think so; at least on Windows it uses the optimal QueryPerformanceCounter API. https://github.com/python/cpython/blob/master/Python/pytime....
comment by pjc50 · 2020-01-18 · in Measure code execution time accurately in Python -
It seems to be enabled by default since 2013/Python 3.4: https://bugs.python.org/issue5845 https://github.com/python/cpython/commit/1a6cb30a346ba8812d6... https://docs.python.org/3.4/whatsnew/3.4.html#sys Support already existed in Python…
comment by duckerude · 2020-01-16 · in Autocomplete as an Interface (2015) -
…conditioned on the fd being 31. From that breakpoint I did a Python backtrace (using the tools from https://github.com/python/cpython/blob/master/Misc/gdbinit ) to figure out the Python code that was responsible for the allocation. The…
comment by nneonneo · 2020-01-13 · in Bug #915: Please help -
It's still like that in CPython: https://github.com/python/cpython/blob/master/Lib/tempfile.p... If there's a strong enough case that this is broken (and the KeyboardInterrupt example is a good one), I think we should file a bug about it.…
comment by nneonneo · 2020-01-13 · in Bug #915: Please help -
…- it really shouldn't... My guess is the tempfile is leaking due to the attribute caching here https://github.com/python/cpython/blob/master/Lib/tempfile.p... . But that doesn't really explain why the file is getting closed twice.…
comment by asdfaoeu · 2020-01-13 · in Bug #915: Please help -
…libuv, like Node - is apparently the fastest asyncio event loop. CPython Asyncio C module source: https://github.com/python/cpython/blob/master/Modules/_async... Asyncio docs: https://docs.python.org/3/library/asyncio.html (When things…
comment by westurner · 2019-12-25 · in Ask HN: Is it worth it to learn C in 2020? -
…and cite to a follow up spec addressing a bug in the initial treatment of negative timezones... https://github.com/python/cpython/blob/master/Lib/email/_par...
comment by iudqnolq · 2019-12-17 · in Hacking GitHub's Auth with Unicode's Turkish Dotless 'I' -
…uses of Ellipsis are actually special-cased; it is not a standard part of the abstract syntax. [0] https://github.com/python/cpython/blob/master/Parser/Python....
comment by lidHanteyk · 2019-12-17 · in A tiny Python exception oddity -
…the venv module added in 3.3 gets the job done. And that does default to symlinks for posix. https://github.com/python/cpython/blob/3.8/Lib/venv/__init__...
comment by more-coffee · 2019-12-07 · in Two malicious Python libraries caught stealing SSH and GPG keys -
Python uses a String conversion to implement rounding, so why not? :) https://github.com/python/cpython/blob/master/Objects/floato...
comment by soVeryTired · 2019-11-11 · in My Favorite Programming Problem to Teach: Digit Length -
Funny fact: the python round implementation actually uses strings. https://github.com/python/cpython/blob/master/Objects/floato...
comment by pd0wm · 2019-11-11 · in My Favorite Programming Problem to Teach: Digit Length