« first day (3280 days earlier)      last day (1672 days later) » 
03:00 - 18:0018:00 - 23:00

3:48 AM
@Aran-Fey the google style guide got updated some time ago, that's where I got most of my opinions from google.github.io/styleguide/…
"""First line <80 characters, one-line description.

If more info is needed, add it the body which may
have line breaks.
"""
Just like Andras
 
 
1 hour later…
5:05 AM
Thank you SO python experts, I just finished building two packages that I've been making at work over the course of an year. I did everything from idea conception to packaging and the company is taking this project to production level. There is no way in hell or heaven I could have done this without SO. Amazing place.
8
 
Can this error ever occurs, irrespective of nature of list F :
if F[len(F) - 1] == ' ':
IndexError: list index out of range
I cannot think of the instance when this error can occur, but I am getting it. I think background details are not necessary, but if you think it needs it, I will provide them.
I know how to get the last element, i.e. F[-1]
Never mind, it can occur, when the list is empty.
 
 
2 hours later…
7:18 AM
@smci hi. i have updated the question can you have a look?
 
 
2 hours later…
8:53 AM
cbg
 
9:27 AM
pypy claims to implement python 3.5/3.6 and yet doesn't have memoryviews with an obj attribute (added in 3.3). smh
 
9:39 AM
strange. memoryviews are mentioned in the PyPy changelog (Py2 only, though) doc.pypy.org/en/latest/release-v5.8.0.html
>>>> memoryviews
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'memoryviews' is not defined
 
it's memoryview without the s
 
dang
>>>> memoryview(b"abcd") works for me
you mean this one? AttributeError: 'memoryview' object has no attribute 'obj'
 
Hey I was wondering is there an ip that will always fail when doing a traceback to it? Like localhost will (always) succeed?
 
@Aran-Fey waiting for the next release: bitbucket.org/pypy/pypy/issues/3016/…
 
9:54 AM
cabbage
if you were here, you could use google IP @Hakaishin - it is guaranteed to fail! O-o
 
heh
 
@Hakaishin This looks relevant. stackoverflow.com/q/10456044/4014959
 
@ReblochonMasque ? Some kind of joke I don't get? Atleast I use 8.8.8.8 as a sanity check :P
Because it works always
 
From behind the GFW, it always fail.
 
@PM2Ring perfect. It is exactly my uscase, but I didn't include the word unittest :P
gfw?
great firewall?
:D
 
9:58 AM
The Great Fire Wall of China
 
@Hakaishin Monsieur ReblochonMasque is behind the Great Firewall of China.
 
hahahahaha
haha wow this is so funny, after their actual great wall they decided to build a great virtual wall :D
sorry, if the laughing is bad. But when bad things happen ppl don't know what to do but laugh
 
How else to stop those pesky virtual barbarians?
 
:D
 
@Kevin A day or so ago you found some dubious astronomy stuff on Wikipedia, which is a bit weird, since WP is usually pretty good on fundamental hard science. But an OP on Astronomy.SE uncovered a real doozy a few days ago in an article about the shadow of the Sun. See astronomy.stackexchange.com/q/33595/16685 for details. It's scary that errors in something that basic went undetected for years. :(
 
10:23 AM
Hello.Not programming problems this time. Probably I have asked this earlier, are there any books which introduce about the algorithmic approach to solve programming problems and introduce some of the major one. I can find those books which are primarily used in academics, like those entitled "Data structure and Algorithms" which seems to me to be heavily academic, but I want something informal type which builds the intuition.
 
10:35 AM
@AjayMishra Good question. I learned this stuff decades ago, and I haven't really kept up with the literature, so I'm afraid I don't have any recommendations. But maybe someone else has some good suggestions...
One of the classics is Wirth's en.wikipedia.org/wiki/… It's over 40 years old, but it was very influential in its day, and some of the material is still very relevant. However, it predates OOP.
 
Programming pearls will introduce you to problem solving with algorithms, but won't list the major algos/data structures
 
Niklaus Wirth was the creator of the Pascal language.
Ah, right! Programming Pearls is (are?) great. And if you want to know about algorithms for graphics stuff, there's Graphics Gems.
 
graphics gems is lovely
 
And since we're talking about classics we have to mention Knuth's en.wikipedia.org/wiki/The_Art_of_Computer_Programming but that's probably not great for self-study. :D
And The Art of Computer Programming isn't designed to teach you to code. It's more about analyzing algorithms and proving that they work, and what their complexity is. Etc.
 
 
2 hours later…
12:25 PM
Why in the world does WeakSet define a function inside it's __init__ method?! At this point they're just purposely making it difficult to serialize weaksets, aren't they?!
 
lol
that's sounds painful
 
Hi I want to ask you can I use PyPy with Python 3.7.2. What an acceleration I can expect. Is there something to know before installs regarding to security.
 
cbg all
 
PyPy doesn't implement python 3.7 yet
 
@Aran-Fey That means I can't use it at all?
 
12:38 PM
you can use it to run python 3.6-compatible code
 
@Aran-Fey OK. Thank you
Have a nice day
 
@PM2Ring sounds too close to perl
 
1:23 PM
cbg
 
@PM2Ring Oh dear. I guess I should do my part and report my findings to the Wikipedia editors. Not entirely sure how to do that, since the problem is spread over 80 pages.
 
print("{:<5} {:<10}".format(core, list(apps)))
TypeError: unsupported format string passed to list.__format__
getting this :/
 
That means that you can't format a list object with the format string "<10"
 
its running in python 2.7
 
Sam
Anyone here familiar with custom layers in Keras. I've got a custom pooling layer which for some reason is returning some -inf values, and I cant seem to understand why
 
1:35 PM
I actually had a similar problem just yesterday. I was surprised to discover I couldn't apply padding to a tuple object.
I don't know if this is the "right" solution, but the quick-n-dirty fix is to convert the object to string before passing it to format
>>> core = 1
>>> apps = [1,2,3]
>>> print("{:<5} {:<10}".format(core, str(apps)))
1     [1, 2, 3]
 
@AndrasDeak Well, Programming Pearls was pretty much an instant success, and it predates Perl by about a year, so it's possible that Larry Wall was "inspired" by Jon Bentley's book...
 
Sam
def mapper(tensor):
tensor, idx = tensor
c1 = tensor[0:idx[0]-1, :]
c2 = tensor[idx[0]:idx[1]-1, :]
c3 = tensor[idx[1]:tensor.shape[0], :]

c1r = tf.math.reduce_max(c1, axis=0)
c2r = tf.math.reduce_max(c2, axis=0)
c3r = tf.math.reduce_max(c3, axis=0)

c = tf.stack((c1r, c2r, c3r))
c = tf.transpose(c, perm=[1, 0])
c = tf.reshape(c, [-1])
return c, 0

The input tensor in this case is a 2D matrix whos values are always finite so I'm not sure if any of these calculations could throw up a `-inf`
 
Maybe there's a type designator you can use to convert implicitly... Let's see
 
@Kevin Me neither. But IIRC a couple of the Physics.SE regulars are also prolific Wikipedia editors. I guess they'd know the protocol.
 
Hmm, perhaps I'll inquire within their chat once I have constructed a more detailed map of the duplicates
 
1:43 PM
@Aran-Fey How... convenient. I must admit I often define helper functions in the __init__ of my GUI classes, but that's different, since I only create a single instance of the GUI. And I've never considered trying to pickle the whole GUI state, just its data, but I guess that could be a useful thing to do.
 
I've defined private functions inside an __init__ a couple of times in my day.
 
@PM2Ring The book was predated by Bentley's monthly column in Byte magazine
 
2:05 PM
Cabbage all
If you have a failed alembic migration, how does one rollback?
 
What is up you snake lovers?!
get it?
cuz Python is a.... ok, I'll shut up
came here to ask a question... but the documentation already answered for me :)
 
You don't have to have an irrational fondness for snakes to be here, but it helps!!!
-- needlepoint sign hanging over the chat room's doorway
 
@OldTinfoil delete the migration script
 
The only snakes I've ever played with were the ones on some Nokia phones
 
@roganjosh Witty
 
2:17 PM
@OldTinfoil The database keep a record of that latest migration that was successfully applied. upgrade looks for any migration scripts that were generated after that particular point. If you delete the script, just rerun the migration and then the upgrade
It wasn't meant to be witty; it was meant to fix your problem :P
Or, at least, that's how Flask-Migrate works and I'm pretty sure it's a thin wrapper that doesn't do anything differently in this regard. I'll have a look
 
In that case, apologies for my sardonic response
 
@OldTinfoil although, we should probably clarify here that "failed" migration is an actual error?
 
Aye. To be specific - the changes to the database executed okay, but some of the post-processing failed. Since I'm using sqlalchemy sessions for the post-processing, that's rolling back as designed if there's an error
But if the post-processing doesn't complete, I would want to rollback some of the changes (like the deletion of a table)
 
@PaulMcG Ah, yes. That brings back memories...
 
Oh, then you would want to run the downgrade then, wouldn't you?
 
2:22 PM
But the downgrade would fail because the upgrade didn't complete fully
Unless I'm doing things with post-processing in alembic that I really shouldn't be doing
 
I'm not really sure what the post-processing is?
 
We're applying different algorithms to process data that we're measuring. This migration adds a new method of processing existing data - so it looks over the old data, applies the algorithm and stores the new values.
 
See, I don't use alembic for any kind of data migration
 
So if you need to transform any of the data based on the incoming migration, where does that happen in your current workflow?
 
Literally just for schema. If SQLA did the rollback automatically, though, you would only need to do a rollback of any schema changes anyway? So the data migration steps can be taken out of downgrade()?
I make my own migration scripts for data. Which may or may not also be the wrong approach :P
 
2:29 PM
@Thaenor An Australian Coastal Carpet Python sunbathing in my back yard a few years ago: i2.photobucket.com/albums/y43/PM2Ring/Snake029.jpg Sorry about the photobucket link.
 
ponders thanks for the food for thought.
So if we go back to the start of the conversation, and I've stripped out all of my post-processing stuff - I would just need to run the upgrade() & downgrade() functions
 
@PM2Ring I would've moved houses if I were you :fear:
 
What if that fails <insert inexplicable reason here>
 
@OldTinfoil If you create a migration script that goes fine, but fails on the upgrade for some reason, the migration should not have been applied at all. There should be nothing to downgrade, and you just delete the script
 
Okay, thanks.
 
2:33 PM
Schema migration*
I'm just checking this now because it's got me questioning myself
 
@Thaenor Why? That snake was more scared of us than vice versa. I tried to get a closer photo, but the snake decided I was too close & slid into the rock wall. He (or she) stayed for winter and then disappeared. People in that district are happy to have a python visit them because they know the python will discourage rodents.
 
@PM2Ring spooky!
 
It could have be Python 4 just arriving... and now you've scared it off... sheesh @PM2Ring :p
 
Pythons aren't venomous, and are smart enough to know that they can't eat a human (except maybe a big python could eat a small baby) so they don't attack unless they're cornered and feel threatened.
 
If the python sees its shadow, the next version release will be delayed by six weeks
 
2:40 PM
@OldTinfoil in this specific case, if the schema migration ran to completion then I think you just need downgrade if you are confident that the data manipulation was fully rolled back. But in reading around, I've realised I'm a bit more cavalier because I'm the only person working on this DB. I never get a failure because of mismatched updates
So my approach of just deleting and retrying probably isn't the best way...
 
Yeah, I think people would flay me alive if I did that badly
haha
 
There's some interesting dicussion about resolving conflicts here
@OldTinfoil what is "team"? Spending every day for the last 2 years working alone with headphones in made me quick to overlook that kinda issue :P
 
I can only assume its someone mistyping "meat"
 
Ahhh, that makes sense
 
I think you're right though. I think I'm trying to get alembic to do too much just now
I probably need to take a step back and develop a proper upgrade system, of which alembic plays a role, but doesn't drive.
 
2:56 PM
 
I read basics of Python and I would like to do a GUI program for Ubuntu. Should I study object oriented programming before it is worth to learn some GUI library?
 
yes, since guis use a lot of oop
 
I wouldn't have said it was mandatory, but I think you'd more likey emerge with your sanity intact
 
meh, I don't think using existing classes requires a whole lot of OOP knowledge
 
Okay. What would be a good learning material for OOP?
 
3:01 PM
You can do smallish GUIs without any OOP, but if you find yourself juggling a lot of globals, it's time to write some classes
 
I second Aran-Fey's message
 
it's true that larger GUIs benefit from custom widget subclasses though
 
I often find myself writing a custom subclass of tkinter.Entry because there's no method to directly set or get the textbox's text
 
@Aran-Fey you mean that s1.data is the same as s2.data?
 
3:06 PM
You can do it with StringVars, but it's a pain in the butt, so I do it once in the body of class EntryEx(tkinter.Entry):, and then never again
 
And if you're writing any Python you're already using objects. It's not that hard to learn how to create your own classes. What can be hard is the shift to event-driven programming that you need for virtually all GUI work.
 
@MisterMiyagi yup. The two sets are effectively the same, just with a different id
 
and you would have expected copy.copy to have disentangled them?
seems reasonable, but I understand why it does not
 
The thing is that WeakSet implements the copy protocol (__reduce__) yet it does it incorrectly
 
that's a gem :D
looking at WeakSet.__reduce__ just made me head-desk...
 
3:15 PM
Thanks for the suggestions!
 
@Aran-Fey it's errors like these that make we wonder why there is no serious proposal for immutability/true-functional for Python
 
@MisterMiyagi this is why I try to avoid looking at stdlib code whenever possible...
 
@JonClements there's already a Python 4 in the works?!
 
Pluralsight has "paths" for various tech. Anyone have any experience with the Python one, and can they share their experience? If so, where did it place you (beginner, intermediate, expert), what's your opinion of the tests, and what's your opinion of the courses it recommended (if you did them)?
 
Was just about to ask a question, but I figured it out while composing the query. Good rubber duck debugging, guys 👍
The answer was "isometry"
 
3:28 PM
Does that mean one-tuples are redundant?
 
@AaronHall I haven't used "paths", but I've scored 289/300 on their python test
 
@Thaenor New versions of Python are always in the works. Eventually, there will be a 4.0. But there isn't a particular significance to the number. It will be as momentous a change as, say, 3.4 to 3.5 was.
 
@Aran-Fey do you think they're adaptive (get questions right, get harder questions, and vice-versa)?
 
We aren't going to have another Python 2.7/3.X schism. Once was enough thanks
 
that was a pretty long time ago (1-2 years?), but if I remember correctly that was indeed the case, yes
well, at least it seemed that way
 
3:33 PM
the nice thing about adaptive is it's much more efficient.
I also noticed some mistakes in the questions, they told me they made corrections based on my comments...
 
I'm
>>> import pygame
pygame 1.9.6
Hello from the pygame community. pygame.org/contribute.html
>>> pygame.init()
(4, 2)
>>> pygame.display.list_modes()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pygame.error: video system not initialized
I'm on Windows 10, WSL, Debian.
I have pygame installed on Windows too and there is no problem, so this has to be a Debian issue.
 
@JohnnyApplesauce I don't know much about pygame, except that lining up the requirements so everything works is tricky - so I wouldn't expect WSL to work out of the box. If you need it to work on debian, try a native system?
 
turns out people've been aware of the weakset bug for 2 years
 
I can confirm that JohnnyApplesauce's code runs without crashing on my Windows 7 machine, so it does seem to be an OS-specific issue
I notice that my pygame.init() returns (6, 0). If init returns (4, 2), that means that some of pygame's components failed to load.
 
3:41 PM
Um
Don't you need to init the display?
 
@Aran-Fey I chuckled a bit when it said basically "we cannot remove it because someone might use it for copying"...
 
pygame.init() is supposed to init everything on your behalf, but I'm guessing it isn't here
 
You know what, I'll shut up. bbiab, switching to *nix
 
pygame.org/docs/ref/pygame.html#pygame.init indicates that there is a way to initialize each component individually, but I'm not sure how exactly one does that. It would be worth looking into, since the individual initializers might give more detailed error information
 
4
Q: Python: running pygame through Bash on Ubuntu on Windows

Null SaladI've recently installed and have been playing around with Bash on Ubuntu on Windows. For the most part it works great. I'm trying to run a pygame script through BUW but it doesn't render the graphics in a popup window. Instead, it seems to be contained in the bash window and looks like this: I...

 
3:44 PM
@JohnnyApplesauce try pygame.display.init() and see if that emits any interesting error messages
 
@Aran-Fey I'm always vaguely aware that there are some shambling mummies in the stdlib, but didn't expect them to lurk that close to the surface
 
Before I move further
 
I use weakref quite a lot
 
What version of SDL does pygame use?
 
I think pygame.org/docs/ref/… will tell you that.
Mine uses (1, 2, 15)
 
3:46 PM
It does not say
The more pertinent question:
Which version of SDL must be used?
Should I simply use the most recent?
 
If by "It does not say", you mean "When I call pygame.get_sdl_version(), it returns an empty string", that's pretty concerning
 
I meant the docs
 
You are printing the result, right? print(pygame.get_sdl_version()) will show the version on the console, and just pygame.get_sdl_version() by itself will not
 
I mean to ask waht I should be doing
 
Okay, on my Ubuntu install.
 
3:48 PM
Not a description of present reality
 
import pygame
pygame.init()
print(pygame.display.list_modes())
works for me
 
(1, 2, 15)
Is this the version I should have?
 
If by "It does not say", you mean "the documentation doesn't specify the minimum allowable version of SDL I can use", I agree -- I can't find that information either
@JohnnyApplesauce Well, your version number is identical to mine, and mine works, so yours should work too.
 
I'm also on (1,2,15)
Let's go back a step, what is the output of your pygame.init() ?
 
UX golf: what's the fastest way to log out from chat?
 
3:57 PM
sledgehammer
 
par is 5 clicks: click your own avatar -> profile on SO -> hamburger -> log out -> confirm
 
wim
@Kevin kind of makes sense, though, because the tuple itself can't tell you how wide it will be
 
"all rooms" -> Stack Exchange -> log out
 
Why not? I can imagine a hypothetical __printable_width__ method, and the tuple object has all the information it needs to return a sensible value. Or does it?
 
@OldTinfoil nice!
 
4:02 PM
return 2*len(self) + sum(item.__printable_width__() for item in self), or something along those lines
 
@Kevin that might change if any item is mutable.
why not pad the result of str(kevin_tuple)?
 
a = [1, 2, 3, 4, 5]
b = [10, 11, 12, 13, 14]

t = (a, b)

b[0] = 2**2048
 
wim
@Aran-Fey pretty weak implementation
 
ugh... looks like I got kevin'd
 
4:08 PM
@MisterMiyagi Ok, sure. But that doesn't seem like a sufficient justification to disallow it. If it was, we would also forbid tuple from having a __repr__ implementation, because that too can change if any item is mutable.
 
wim
@Kevin consider an obj which changes its length when responding on each call of repr
class Obj:
    def __repr__(self):
        return random.choice(['x', 'yy'])
 
@Kevin umm yeah... but that's okay and catered for... even self references for instance are handled in __repr__...
 
wim
obj = Obj()
tup = (obj,)
 
@Kevin but the __repr__ result is usable by itself. a __repr_len__ could change by the time you need it for __repr__
 
wim
a tuple can know how long it is, but it can't know how long it will print without asking each and every element
 
4:11 PM
Ok, sure. But this is all tangential to the main issue. The tuple-padding-allowed version of str.format that I'm envisioning doesn't neceesarily have to call __repr_len__ before calling __repr__. In fact, that's dumb, forget that completely. It simply calls repr, checks the result's len(), and adds padding characters as necessary
 
if you need the len of repr to do something with repr, call repr, store it and get its length.
 
This absolutely must be possible in principle because it's what 2.7 actually does
(or something like it)
 
f'{(1, 2, 3)!s:<10}'
I guess the reason this does not work is that string formats are interpreted by the type, not format/f'. So basically every type would have to understand <10 separately.
 
wim
@Kevin interesting, it raises deprecation warnings though
 
quick question: i'd like to write an infinite-loop such that it's easy to unit test. this means putting everything that's inside of the loop within it's own separate function, and testing that function-
how can i do this if what's inside of the loop has a break statement, though?
trying to define a function w/ a break statement outside of a loop produces a SyntaxError
 
4:18 PM
@MisterMiyagi Hmm, not a bad justification.
 
wim
looks like it was object.__format__ handling that, not tuple, and bugs.python.org/issue7994
 
@OldTinfoil Mine returns (4, 2)
 
@AmagicalFishy huh... maybe I'm having a blonde moment - but how would that work?
 
@AmagicalFishy Perhaps you could redesign your logic so it raises an exception instead of breaking.
 
i don't know: that's why i'm asking :D

the case is something like:

while True:
[do some stuff]
[break if something happens]
 
4:20 PM
@AmagicalFishy how about while body(): pass loop?
so body() returns a bool whether to resume or not
 
oh, that's a pretty good idea.
do you know offhand whehter or not that will affect performance a bunch?
(performance is an issue, so that adds another constraint)
i can test it myself, but it'd save me some time if you knew :D
 
@Kevin I've just had several hours of making up shit on the fly. I feel pretty qualified for wild guessing at the moment.
 
@Aran-Fey
 
rule of thumb: the performance of testing a bool versus a function that does anything nontrivial is negligible.
 
4:22 PM
@AmagicalFishy, so something like:
#old version
while True:
    do_thing()
    if phase_of_moon() == "full":
        break


#new version
class LoopTerminated(Exception):
    pass

def do_thing_and_check_phase():
    do_thing()
    if phase_of_moon() == "full":
        raise LoopTerminated

try:
    while True:
        do_thing_and_check_phase()
except LoopTerminated:
    pass
 
ahh okay... I probably mis-read that... I was thinking how could you prove that something will run infinitely....
 
wim
@piRSquared leaving rooms is not logging out, is it?
 
/-: maybe not
 
i'm going to go w/ the return statment, @Kevin (since i'm working on someone else's code, i'm not sure if an exception raised here would affect anything else)
 
except: pass is usually a blaring red antipattern but it does have its uses when you're just using exceptions to enable an unusual style of control flow
 
4:24 PM
yep, you're still logged in after clicking that
 
oh well
 
@AmagicalFishy A LoopTerminated raised here shouldn't affect anything else, because you are always catching and silencing it. There shouldn't be any circumstance where it bubbles up into other areas of the code
 
oh cool.
is there a benefit to using an exception over a return value?
(or is it just a matter of preference at that point?)
 
wim
you just need to learn how to do mocking
 
What does it mean if pygame.init() returns (4, 2)?
 
wim
4:27 PM
during test setup, you mock something within the loop which will cause the break condition
 
Hmm, now that I think about it more, an exception probably isn't appropriate here. The benefit of the exception approach is that it can move up through multiple layers of control flow, but you've only got 1 or 2 here, so you may as well use conventional control flow elements instead
 
If I do it from Windows command prompt, it returns (6, 0)
 
def do_thing_and_check_phase()
    do_thing()
    return phase_of_moon() == "full":

while True:
    if do_thing_and_check_phase():
        break
 
It just says (4,2) for Debian WSL
 
wim
and if you really want to cover all bases you can use pytest-timeout plugin to prevent the test suite hanging on infinite loop in case of bugs in your test logic
 
4:28 PM
@JohnnyApplesauce Like I said earlier, it means that some components of pygame failed to initialize. Two components, in particular.
 
OOHH!
So How do I Find OUt what thoe Components are?
 
The most likely culprit is the display component, which is why I asked if pygame.display.init() produced any interesting errors. Have you tried that yet?
 
wim
note: if you're doing testing properly, your tests don't really have any logic. so it's pretty hard to write bugs in the tests.
 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pygame.error: No available video device
 
Excellent, a traceback. This is a useful clue.
 
wim
4:32 PM
@AmagicalFishy this is still the best and most readable code IMO ("#old version"). And it's still easily testable.
 
The first google hit for that error message is stackoverflow.com/a/46941642/953482, so try the top-voted answer and see if that helps
 
i think i'll go w/ that @wim , yeah
 
I have a bad feeling that it will allow pygame.display to initialize, but then it will think you have zero monitors, and refuse to actually draw anything. Still worth trying though.
 
Oh dear! Must I do
import os
os.environ["SDL_VIDEODRIVER"] = "dummy"
 
thanks very much, you & @Kevin :)
 
4:33 PM
Every time?
In every file?
Hold on, I will test that in the one I ahve
 
Not every file necessarily. It only needs to execute once at the beginning of the lifetime of the program. So once at the top of your main .py file should suffice.
 
wim
you would set up a mock in [do some stuff] which triggers the [break if something happens] condition
it doesn't necessarily have to trigger it on the first iteration, either
mocks can configured to behave differently on subsequent iteration by using the side-effect
 
Okay, I tried executing it from Windows and it didn't draw anything; let's try again for debian
 
wim
>>> from unittest.mock import MagicMock
>>> m = MagicMock(side_effect=[1, 'potato', Exception("boom")])
>>> m()
1
>>> m()
'potato'
>>> m()
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
...
Exception: boom
 
Well, it doesn't crash
But it doesn't do anything either
 
4:38 PM
@wim do you mix unittest and pytest?
 
@JohnnyApplesauce I was afraid of that. So that code is effectively redirecting all of your rendering calls into a black hole. Good for silencing errors, bad for actually seeing results on your monitor.
Browsing through the other google results, I see one or two people that claim they fixed it by uninstalling and reinstalling SDL.
 
@wim s/testing/unit testing/?
 
4:53 PM
How do you uninstall on Debian/Ubuntu
 
as a Windows user, ¯\_(ツ)_/¯
Perhaps unix.stackexchange.com knows, although they may sigh heavily and roll their eyes before helping
The help may also be in the form of a LMGTFY link
 
wim
@piRSquared no. pure pytest
 
thought so
 
wim
I’m not sure why the mock APIs are under the unittest namespace
 
Ew, LMGTFY got a weird redesign since I last visited it a year ago
Now it's got Branding and stuff
 
4:58 PM
heeheeheeheehee
Being passive-aggressive just got harder...
 
Maybe they got in trouble for having the Google logo in their smarmy search animation
 
wim
What’s LMGTFY ?
 
Let
Me
That
For
Google
 
5:00 PM
@Kevin meta LMGTFY
I like @jas's version though "Let me that for google you"
 
wim
It was a rhetorical question
 
I thought it was a straight-man setup, like "who's on first?"
You ask an innocent question, I give a wacky answer, my bowtie spins, the audience claps
 
*claps*
 
Is there such a thing as an over emphasized sarcastic wink emoji?
 
I think there's a photoshop filter for that
 
5:16 PM
<sarcasm><h1>Right! I gotcha ;-)</h1></sarcasm>
 
wim
new spacesuits, cool or nah? spaceflightnow.com/2019/10/07/…
 
@PM2Ring thanks
 
@wim No frills and practical == Cool, in my book
 
wim
...so you don't want to invest in my startup of frilly spacewear?
 
5:23 PM
nuh-uh
 
are you sure? it will be pretty cool.
cbg folks, how's everyone!
 
Frilly spacewear will undoubtedly be popular in the impending interplanetary travel boom of the 23rd century
 
@Kevin Any reason in particular for creating a LoopTerminated exception instead of using good old StopIteration ?
 
5:33 PM
Funny thing is that it will be largely based on the futuristic stylings of the 1970s disco era
 
@PM2Ring I was paranoid that do_stuff might actually use iterators, and in some circumstances raise a StopIteration that should not be caught by this try-except
 
wim
@PM2Ring StopIteration are not caught by while loops
 
OK! I'm done... I promise
 
wim
 
5:37 PM
@piRSquared thanks
 
I'm struggling to think of a use-case where do_stuff would intentionally raise an uncaught StopIteration, but it's easy enough to contrive a scenario where do_stuff is buggy and unintentionally raises one. We'd prefer the exception to go uncaught and unsilenced, for the sake of easy debugging.
 
Hi to all, cbg
 
wim
IIRC you're not supposed to raise stopiteration
if you do it in a generator it gets transformed into a runtime error !
 
StopIteration is a bit spooky to me so I keep a wide berth
SystemExit too
 
wim
good
use return statement for the former, and sys.exit for the latter
 
5:45 PM
Yeah. In practice I almost never call exit, though. No shortcuts, we reach the bottom line of the script or die trying
 
Hi again,
Why does collections.Counter does not implement the `<` operator?
Set implements it for example `{1} < {1, 2}` returns `True`.
It only seems fitting as Counter implements intersection (&) and union (|).
Is there any reason for that?
 
wim
pretty good question
 
dict used to have inequality support, in 2.7. I guess whatever motivated them to remove it might also apply to counter
 
wim
this is probably 2.7's fault
since counter is a dict, and dict already had a < implementation
 
one more question:

in *A* i have "from flask import current_app" and then "current_app" is used in some class definition

now, i want to test A, and i want to patch out "current_app" so that it returns a dummy class
 
5:49 PM
Even though on a conceptual level a counter is more like a set than a dict. Arguably.
 
an instance of a dummy class*
 
@Kevin Fair point.
 
i thought it was just:

@patch('flask.current_app', side_effect=DummyClass()), but this doesn't work
 
wim
it may have been better design for counter not to inherit dict
it's more like a multiset or bag
 
neither does @patch(A.flask.current_app, side_effect=DummyClass())
or any permutation of this
 
wim
5:49 PM
it kind of got overloaded to be two things, this class is having an identity crisis
 
which seems contrary to what i think the documentation is saying
 
@wim True, but while loops don't catch LoopTerminated exceptions either. ;)
 
Thanks @Kevin and @wim
 
@wim I guess it doesn't inherit anymore
>>> Counter({'a': 2, 'b': 4})
Counter({'b': 4, 'a': 2})
or perhaps it's just designed to put most common first, I've never payed that much attention to it
 
wim
@AndrasDeak it still inherits dict
 
5:52 PM
OK
 
wim
look at the repr implementation
 
I'm trying to find it as we speak
 
wim
type in >>> Counter.__repr__?? in your IPython session and press enter
 
right
# Outputs guaranteed to only include positive counts.
#
# To strip negative and zero counts, add-in an empty counter:
#       c += Counter()
some nice confusion fuel there ^
Speaking of PEP 257, call the police
 
03:00 - 18:0018:00 - 23:00

« first day (3280 days earlier)      last day (1672 days later) »