Not exactly a help post
Can you guess what this one does or how exactly it does it?
rgenkeys = lambda s=2048, e=65537: ((lambda obj1, obj2: (obj1, obj2.public_key()))(*((lambda obj: (obj, obj))(rsa.generate_private_key(public_exponent=e, key_size=s)))))
No guessing required.
It annoys and frustrates the reader.
By being an obnoxiously obfuscated one-liner using multiple nested lambdas.
Here is a more or less exact translation of the code:
def rgenkeys(s=2048, e=65537):
def duplicate(obj):
return (obj, obj)
def inner(obj1, obj2):
return obj1, obj2.public_key()
t = rsa.generate_private_key(public_exponent=e, key_size=s)
return inner(*duplicate(t))
And here is how it should have been written:
def rgenkeys(s=2048, e=65537):
t = rsa.generate_private_key(public_exponent=e, key_size=s)
return (t, t.public_key())
3 Likes
Quercus
(Quercus)
February 26, 2023, 11:42pm
3
Hello, @DiamondDemon , and welcome to Python Software Foundation Discourse!
It causes the reader to submit the following at the interactive Python prompt, and then to consider which lines among the response can serve as guidance:
>>> import this
dstromberg
(Daniel R Stromberg)
February 27, 2023, 12:35am
4
Most code is read more than it was written, so saving a little time while writing things is a false economy.
Rosuav
(Chris Angelico)
February 27, 2023, 1:28am
5
I can’t imagine that this was written faster than a more simple function would have been. It looks like it was deliberately obfuscated just for the sake of posting here.
dstromberg
(Daniel R Stromberg)
March 1, 2023, 9:34pm
6
In a past job, my boss’, boss’, boss’, boss said to “never attribute to malice that which can be attributed to stupidity”.