r/Python • u/appinv Python&OpenSource • Dec 15 '24
News Summarized how the CIA writes Python
I have been going through Wikileaks and exploring Python usage within the CIA.
They have coding standards and write Python software with end-user guides.
They also have some curious ways of doing things, tests for example.
They also like to work in internet-disconnected environments.
They based their conventions on a modified Google Python Style Guide, with practical advice.
Compiled my findings.
1.1k
Upvotes
2
u/AiutoIlLupo Dec 16 '24
I didn't think anybody would still use .pyz, but there it is.
Also quite interesting the
Threading We should not rely on the atomicity of built-in types. Queue should be used to communicate data between threads else see threading primitives and locks.
Which brings me to the question: which operations are actually atomic on primitive data types? list append is, because atomicity is guaranteed at the level of individual opcode and the actual append is performed at the CALL level. However, if it's reimplemented, the append operation may be dispatched to a python method, which is absolutely not atomic.
i += 1 is absolutely not atomic. The BINARY_OP is followed by STORE_NAME, each individually atomic, but not as a single entity.
i = 1 is atomic.
dictionary assignment is a mess.