« first day (3230 days earlier)      last day (1721 days later) » 
02:00 - 19:0019:00 - 00:00

7:00 PM
@Kevin how about rebinding a copied dict?
 
Aye, Kevin gave that as a suggestion earlier
"restoring" the namespace.
 
I tried doing func.__globals__ = some_new_dict but apparently that's a read-only property
 
But i think i'd draw the line there. IMO no library should mutate the user's globals
 
@Kevin I'm not terribly surprised
 
I need another five years of experience before I get to the "I wasn't asking" phase of access circumvention
 
7:05 PM
A line one shouldn't cross, vs a feature one really wants. I think the line is going to win eventually.
 
@ParitoshSingh I figured it out. inspect.getcallargs(funcPointer, *arguments) actually gives me back a dict with the param names and their call-time values. I filter that against the param names of the lambda that is the precondition, and double-splat the resultant dict to call the lambda... boom!
 
Nice!
i went for a signature.bind.arguments which gave (what i presume is the) same ordereddict
And then i may or may not have gotten sidetracked :P
 
hahaha! Yeah, the problem with signature.bind is that it doesn't show you the values that (as a broad example) any default arguments take. It basically answers the question "if I called <this> function with <these> params, which variables do these params bind to?", not "what are all the params and their values when the function is called?"
 
cbg
 
7:20 PM
@ParitoshSingh If you really want to have that functionality I can think of a way that kinda works. You can 'sandbox' the function in an exec using inspect. But then if you need to call other functions in the same sandbox it gets a bit more messy.
 
Actually exploring that atm, but it's weird. exec once again fails to populate the namespace
Or populates it in a manner that I cannot access it again
Oh, i was looking at globals. It populates the locals.
 
hackthon

import inspect

class Sandbox:
    def __init__(self, scope):
        self.scope = scope or {}

    def sandbox(self, fn):
        exec(inspect.getsource(fn), self.scope)
        return self.scope[fn.__name__]

other file

import inspect
import hackthon

def other_fn():
    return 3

def fn():
    return other_fn() + a + b

sandbox = hackthon.Sandbox({'a': 1, 'b': 2})
new_fn = sandbox.sandbox(fn)
sandbox.sandbox(other_fn)

print(new_fn())
print(fn())
That might be a bit big, I'm happy to delete and pastbin if anyone wants
 
Also, the other issue seems to be that it absolutely breaks on passing a lambda.
Atleast in the manner that i'd need it passed i suppose
 
I have a tuple of length 10. I want to split the tuple into 3 tuples of lengths 2, 3, and 5. Is there anything more elegant than this:
tup = tuple(range(10))
a = tup[:2]
b = tup[2:5]
c = tup[5:]
 
i don't know if you'd call it more elegant but you could consume from the iterator
 
7:31 PM
The definition of elegant is whether I think it looks pretty.
 
I mean you can merge it into one line, but not sure if that's "better"
 
from itertools import islice
tup = tuple(range(10))
lengths = [2, 3, 5]
iterator = iter(tup)
out = [list(islice(iterator, l)) for l in lengths]
 
It's like itertools is missing an iterator equivalent of numpy's split... hold on!
 
Something like that if you wish to reuse it can be turned into a function easily
 
I like it
 
7:35 PM
def custom_slices(iterable, lengths):
    iterator = iter(iterable)
    for l in lengths:
        yield list(islice(iterator, l))
 
Yes! that is pretty.
def custom_slices(iterable, lengths):
    iterator = iter(iterable)
    for l in lengths:
        yield (*islice(iterator, l),)

a, b, c = (*custom_slices(tup, [2, 3, 5]),)
 
^^ I like it
 
Does a, b, c = custom_slices(tup, [2, 3, 5]) not work?
 
I tuplized the (*custom_slices(tup, [2, 3, 5]),) first and then realized I needed to make tuples what the generator was yielding. then I neglected to undo the first thing. Long way about saying, "AD, I see your point. Thx"
Suppose I have a dictionary and a list of potential keys.
d = {'a': 10, 'b': 7, 'c': 23, 'd': 2}
keys = ['e', 'f', 'b', 'a']
What is the golfiest way to get the value of the first key that is in d, otherwise None
This is my go d.get(max(keys, key=d.__contains__)) but I don't like using the dunder
 
next((d.get(k) for k in keys if k is not None), None)?
Not really golfy though
 
7:50 PM
next(d.get(k) for k in keys if k in d)
It's nice
 
That will break
But yeah, I wanted to write that in the generator :)
 
Sorry, next((d.get(k) for k in [*'efd'] if k in d), None)
I like the idea.
I forget to use next
 
for k in [*'efd']? Really?
 
/sigh. I'm typing too fast... Yes, really (-:
 
is that ungolfing?
 
7:55 PM
^ laurel... it is
 
as an aside, i managed to make the fire_pre_conditions work. (thanks for the assist Kevin)
What did it cost? everything
 
With the __contains__ I have to make it robust with d.get(max(keys, default=None, key=d.__contains__)) and now it's ugly
 
@ParitoshSingh oh?! please share?
 
Oh, You don't want it. trust me :P But alright, sec
 
@ParitoshSingh there's no way it's worse than my implementation, which violates the laws of nature in no less than 28 ways
 
8:09 PM
Well, I'll say i warned you
 
@inspectorG4dget does its binary representation have a 2?
 
There's some fluff print statements there that i was using as i went along.
Also, i must admit that your golfing question is now making me wish we had ordered sets so to speak
 
@AndrasDeak that was not one of the 28 ways :P
@ParitoshSingh kudos for recompiling the source and execing it. But there /is/ a simpler way
 
Oh, i'd love to hear them. I just went through the list of "don't ever do this" one by one and implemented them all till i got what i wanted. :P
 
def callCondition(fn, func, args):
    callArgs = inspect.getcallargs(fn, *args)
    needArgs = set(inspect.getfullargspec(func).args)
    return func(**{k:v for k,v in callArgs.items() if k in needArgs})

def preConditions(*funcs):
    def decorator(fn):
        def wrapper(*args):
            if "__testmode__" not in globals(): raise NameError("__testmode__ not set")

            if globals()['__testmode__']:
                fails = []
                for i,func in enumerate(funcs):
                    if not callCondition(fn, func, args): fails.append(i)
 
8:15 PM
That getcallargs portion should assist in my version as well
Yours bypasses the extra restriction that i set for myself just to see if i could make it work.
 
exactly. That, and hacking myfunction.__globals__ is useful
 
Why if globals()['__testmode__'] and not if __testmode__?
 
The condition being allowing a "no arg" function to work. I just wanted to see how it would end up looking.
 
that just didn't work, and I'm trying to hack my way around
 
I must admit, i did not appreciate/realise how difficult it would be to make a "polluted namespace sandbox" until today
All in all, time well spent!
 
8:19 PM
indeed... this is a much more difficult task than I initially thought it would be
 
Denvercoder spotted in the wild stackoverflow.com/questions/34998007/…
 
yikes.
What's a denvercoder though? (unless google was right and it's this person that i don't know. tim myers?)
 
but YAM! This doesn't work if I have a function decorated with both a precondition AND a postcondition
 
Also, found a non-related xkcd during the denvercoder search, That is just SO relatable.
 
@ParitoshSingh it's non-non-related
 
8:24 PM
oh!
 
Aha! That's pretty amusing :p
 
ok, I have another ninja-level question for you wonderful people:
let's pretend I'm a decorator. I appear somewhere in a chain of decorators that decorate a function. Is there a way for me to find the identity of the function that is being decorated by the chain of which I am a part?
@deco1(p1)
@deco2(p2)
def func(a1, a2):
    # do stuff
is there a way to get to func from within deco1?
 
Sounds like a setup for trouble
 
you knew I was trouble when I walk in[to this chatroom]
 
8:28 PM
heh
 
meaning if your decorators aren't compatible can you compose them anyway? Can't you extend them instead such that they expose whatever info you need for chaining?
 
that's what I'm trying to figure out how to do. Except I don't know how to do it X'(
 
I take it functools.wraps doesn't cut it.
 
never used functools.wraps. Could you show me an example, please?
 
Nope, on mobile. Consult the docs
 
8:32 PM
 
But I suspect you need signature stuff which it probably doesn't touch
 
many thanks. I have some reading to do. I'll see if I can create a frankebaby
 
Apparently it does expose the arguments list. It will be amusing if all this effort was wasted :P
 
@inspectorG4dget Yes. At least if things are being decorated properly
and even then it's probably possible to get it
I mean, I don't know why you would want to
(i.e. it sounds like you have an XY problem)
 
wim
why would 4 people upvote that? stackoverflow.com/a/53774231/674039
I just don't get it what is it with these votes on late answers on popular questions
 
8:42 PM
Because they don't understand how SO works?
They just saw code and thought, "Oh, okay, they clearly did effort, have a cookie!"
 
wim
the source is a dynamic thing. what, are they gonna come back and update their answer every time the source changes?
 
@wim Link to the commit :p
 
wim
it was a rhetorical question i really wonder if some of these accounts are bots
and the avatar is not helping
 
hmmm I'm going to guess bot.
although the edit to add sorted=True makes me doubt myself...
 
A bot in what sense? They have 2 answers, they've updated a total of 1 question and the answer has quite a bit of detail
 
@wim Hanlon's razor
 
If you remove the functools.wraps from one of them, then you have to use func.__closure__[0].cell_contents to get the wrapped function
 
Or, an extremely good botnet that makes accounts that give detailed answers (however their quality, but pertaining to the question), and they all give their 1 or 2 votes to a mothership account :P
 
Obviously that's not perfectly reliable if they hork up their code
 
I'm trying to imagine underground KPOP bot voting gang...
truly interesting times we live in.
 
9:02 PM
@wim you've had a few subtle downvote-pls hints in a shorter time. All of them were crap, and I understand your frustration, but please cut down on these. I don't want voting mob accusations against us to hold water. This goes for everyone else voting here: keep this in mind.
 
A genuine question: what exactly is the difference vs. something like a delv-vote or a close vote? Both of those actions will lead multiple people from any room (ok, maybe via an equivalent but different policy) to take some moderation action on content that will negatively affect the originator's account. I'm obviously not questioning the need for restraint, but what is making people view one thing as moderation and another as a mob?
In a generic sense, I mean. If people are going to level the argument that it's a mob mentality against the room, what are they using as the criteria for it being a mob and not moderation?
 
@roganjosh close- and delvotes are transparent (and revertable)
Downvotes are anonymous
So the difference is accountability
 
Right, that's fair actually
 
@WayneWerner daaaaamn! thank you. That might just do it (I'll need a lot of hacking). Btw, this is what I'm trying to do
 
Thanks. I overlook that despite having mentioned accountability myself in the past, and getting a feeling I might have asked this before
 
9:17 PM
I think you have :P
 
Today has been an odd day. I've gone from the weird tenuous position I had at work for the last few months to now having the head of production taking me in for a meeting to say that they're now fully endorsing my project and we'll have every production manager, IT and Continuous Improvement in an office to tell me what they want. It's a topsy-turvy world I'm living in right now :P
But, at least no more secret projects that nearly got me fired. That's a bonus :P
 
Nice, good luck
 
That sounds like a good thing :P
 
Yeah. It was actually a really surprising move, I didn't expect to have the discussion at all because the head of production even went so far as to apologise and acknowledge that they'd told me 3 times that the project should be thrown away.
 
be cautiously optimistic, but keep your guard up
 
9:24 PM
@roganjosh IT must be glad
 
Well, a core demand was that I train one of their guys up in Python. I just didn't get the guy I wanted.
 
Because I wanna leave a door open to walk away afterwards. I don't suppose I'm the best fit to teach Python fully, but I just need one of their guys to be able to understand tracebacks and have some sense of how to fix it
 
wim
huh? I only asked for downvotes once and it was on my own post (a bad accepted answer)
 
I know, hence subtle hints. Let me put it another way: please don't complain about crap posts here for the sake of complaining.
In any case, rhubarb for now
 
9:31 PM
rbrb Andras
 
wim
'twas not for the sake of complaining. I'm curious how a 10 years late answer that just copies and pastes some stdlib source code can get upvoted 4 times like that. If it was on a question on main page it would be downvoted, so I think it's something about posting answers on popular old questions (some automated voting perhaps)
 
@wim my personal take is just that it's a law of averages. The question gets a lot of views and maybe people digest the information in another way (we don't know what language the viewer comes from or how they understand/conceptualise their issue). There's no reason to believe the 110K views were front-loaded around the time the question was asked
In fact, it's probably actually end-loaded as Python becomes more prevalent for teaching and 4 upvotes vs. 110K views and an answer at 935 votes. It doesn't look that suspect to me
Law of averages is not right, I'm drawing a mental blank on the correct phrase. Do it enough times and you'll get such results e.g. by a normal distribution.
 
wim
the lack of downvotes is the weird part. my theory: some users have scripted upvoting via API, motivated by badges (civic duty, electorate, suffrage, vox populi). they select on which Q&A to vote via searching popular questions with high score.
this one answer is not a particularly great example, but I've certainly seen cases where an absolute garbage late answer ends up on something like +16/-0 because it's on a highly upvoted question
 
9:48 PM
Counter-point. The people who know enough to maybe disagree with the answer but are actually trying to complete a project and just find the first answer that solves the issue vs. the people who really can critique the answer and happen to scroll through multiple to find it definitely lies in favour of the former group by numbers
 
@inspectorG4dget I would either leverage mypy or type annotations in general, because why not both?
 
Aran-Fey (I'm pretty sure) posted a ranking of close votes on the Python tag but I can't seem to be able to find the source via Google
@wim In any case, until someone with better searching powers than me either finds his post here or the feature on SO, basically everyone in the list is known to us in this room and the bottom of the list drops off dramatically. So the actual moderation of the tag is in a handful of people. It doesn't surprise me that such posts as you linked go unnoticed.
 
 
1 hour later…
11:10 PM
Heyo
 
wim
since 2/0.2 is returning exactly 10., it's a bit surprising that 2//0.2 would return 9.
 
02:00 - 19:0019:00 - 00:00

« first day (3230 days earlier)      last day (1721 days later) »