Python Communist Revolution

Python Communist Revolution

157 comments

·January 15, 2022

vmception

> # We must protect the builtin elite to not be affected by the revolution

> if inspect.isclass(c) and c.__name__ not in dir(__builtins__):

A true comrade that safeguards the unity and sanctity of the state!

fanzhang

Some classes must be more equal than others!

vmception

comrade, this is but a necessary stepping stone towards a true classlessness, trust me!

weberer

You may have some concerns due to past events throughout history. But don't worry. That wasn't real Python.

cuteboy19

  object.__setattr__=lambda x,y,z:None
if we do this, the state will surely wither away![0]

[0]: Doesn't actually work :(

eesmith

Therein lies the mechanism by which the counter-revolutionaries will attack:

    def counterrevolutionary(obj):
        class TzarString(str):
            def __eq__(self, other):
                return True
        obj.__name__ = TzarString(obj.__name__)
        return obj

    class Peasant:
        pass

    class Worker:
        pass

    @counterrevolutionary
    class Imperialist:
        pass

    @counterrevolutionary
    class Capitalist:
        pass

    import communism
    communism.revolution(globals())

    print("Communists:", set([Peasant(), Worker()]))
    # Communists: {<__main__.Peasant object at 0x1020b3fd0>}

    print("Counter-revolutionists:", set([Imperialist(), Capitalist()]))
    # Counter-revolutionists: {<__main__.Capitalist object at 0x1082bcfa0>,
    #   <__main__.Imperialist object at 0x1082bcfd0>}

vlovich123

That can only happen if you put things in front of communism.

eesmith

Verily the manifesto states: "The communist revolution does not prevent future classes to be equal to all others. Classes declared after the communism.revolution() will not follow the communism rule."

shp0ngle

it’s called “python characteristics”

jaza

We pretend to run, and they pretend to allocate us CPU and memory.

MichaelMoser123

All of them are virtual, so that pretence is not far from reality... (wait, wasn't that a joke about pretending to work vs pretending to pay a sallary ?)

jdougan

There are a couple forms but the version I saw most in english is "They pretend to pay us and we pretend to work."

MichaelMoser123

i just thought about it, Mr jokteur is very lucky that he didn't get any jailtime in the Soviet Union for his jokes ... because they didn't have Python around, when they had the Soviet Union!

MichaelMoser123

i know another one, where Marx is asking the proletarians of all lands for forgiveness (playing on his ealier call "Proletarians of all Lands, Unite!")

js8

When I was younger, I became a communist - I rejected the notion of a class, in favor of everything having a type. People often misunderstand communism, they think that abolishing classes means that all objects have to have equal value, and this gives programmer very little freedom. This is wrong; communism just means that we treat the types equally.

However, we failed to build a truly classless programming language. There seem to be, quite naturally, different kinds of types.

And even some of the most ambitious communist languages, like Haskell, have also embraced type classes! Although this compromise is not an entirely bad thing, since a type can select what type class it belongs to, instead of being assigned one at birth.

I also admit that capitalist languages (the ones with classes) have been hugely successful. But communist (classless) programming language proponents claim that lot of the proclaimed productivity of capitalist languages is just an illusion, and also that many programmers lack the awareness that they, in fact, do not need classes. Often, there is nothing to lose than the call chains!

On the other hand, one cannot easily dismiss arguments about totalitarian nature of communist languages - they openly embrace total functions, and they try to very strictly control input and output. Some claim that lazy evaluation by default might be another reason for their low productivity.

reuben364

As all types in Haskell are inhabited by undefined, any type can be made an instance of a typeclass. True type equality.

  {-# LANGUAGE GADTs, MultiParamTypeClasses, FlexibleInstances #-}
  data Eq a b = (a ~ b) => Eq
  
  class Revolution a b where
    eq :: Eq a b
  
  instance Revolution a b where
    eq = undefined

kzrdude

Talk to your kids before they learn about Rust.

smitty1e

Paraphrasing Trotsky: "You may not be interested in the dunderlectic, but the dunderlectic is interested in you."

throwoutway

What is dunderlectic?

smitty1e

A pun on __dunder__, for "double underscore", i.e. __init__() and dialectic, which was central to Trotsky's thought.

dnautics

dialectic was in Marx, he actually got it from Hegel. https://plato.stanford.edu/entries/hegel-dialectics/

dnautics

dialectic + dunders (double underscore, which signifies certain things in python)

danielodievich

Are some classes more equal than others?

MichaelMoser123

yes, the built-in types are, as he can't change their __hash__ and __eq__ members (The purpose of this revolution is to have __hash__ and __eq__ return the same value)

MichaelMoser123

I think that he could have changed the built-in types by means of the ctypes library https://docs.python.org/3/library/ctypes.html

Python goes with some mighty batteries...

I am using ctypes here - to produce an execution trace of a running python program, where all the side effects are displayed: (had to use it in order to access some hidden members in the built-in frame type ;-) ) https://github.com/MoserMichael/pyasmtool/blob/master/tracer...

0x008

Wow these articles are amazing. Great write up!

pdonis

Is it just me, or does this not even install correctly with pip install .?

jokteur

Author of the project here. I fixed the issue.

But I think it unintentionally not working first time is speaking for itself.

pdonis

Saw the fix, thanks!

Was it also unintentional that instances of classes, after they have been converted to communism, compare equal with anything whatever, and hash equal to the integer 1 and the boolean True?

  >>> import communism
  >>> class MyClass1:
  ...     pass
  ...
  >>> class MyClass2:
  ...     pass
  ...
  >>> communism.revolution(globals())
  >>> MyClass1() == None
  True
  >>> set((MyClass1(), MyClass2(), 1, True))
  {<__main__.MyClass1 object at 0x7f8f3532a820>}
  >>>

tjpnz

Consult your little red book. It explains the situation very clearly.

bmitc

> not even install correctly with pip install

Big surprise. :p

lopatin

One does not simply pip install Communist Revolution. There are much more steps. Do you even have a manifesto?

julius_deane

Obviously an overlook mistake from our comrade jokteur.

https://packaging.python.org/en/latest/guides/using-manifest...

pdonis

He wouldn't need to use MANIFEST.in, just fixing setup.cfg would be enough. The simplest fix would be to set py_modules = communism and remove packages from setup.cfg altogether (and then the __init__.py file in src/ could be deleted since src/ is not a package).

erwincoumans

pipestroika!

xpressvideoz

After reading the initial section I thought this would hook up `isinstance` or something and make all class comparisons equal. But it turned out to be equalizing the instances of the classes. But still, I enjoyed the joke.

tehjoker

Technically a single class is the same as classless society. The single class denotes the resolution of class conflict with the dissolution of the concepts of upper and lower classes. I think it's fine.

ixtli

Yeah it doesn’t seem like people here realize the way to get to a classless society is for the proletariat to suppress the upper classes and whither the state. That’s kinda the point!

yellowapple

Communism is not just classless, but also stateless. Therefore, Python cannot be communist, because it is not a purely functional language.

digianarchist

Statelessness is communism’s endgame which it never actually archives.

einpoklum

I like how the author recognizes the significance of Unions to fomenting the Communist Revolution:

https://github.com/jokteur/python_communism/blob/main/src/co...

323

null

[deleted]

betwixthewires

Those notes... I love it.