« first day (3981 days earlier)      last day (967 days later) » 

4:12 AM
Hi everyone!
I have an old django 1.9 application with python 2.7
I'm now going to upgrade it to django 3.* with python 3.7
can anyone tell me the challenges i would face in order to do that? Just wanted to be prepared before diving into the upgrade
it's a huge application
Any help is appericiated,Thank you
 
 
1 hour later…
5:30 AM
cbg
@HabibRehman hi, if you have not looked at this then it might be useful
 
 
2 hours later…
7:08 AM
should I type hint a json response as just response_json : dict[str, list] or should I also type hint the nested contents?
 
if it's easy to typehint the list, go for it. if it's hard, say to yourself "ugh i hate typing" and then don't hint it. saying the words is a critical part of the process, recommended by PEP<redacted>
 
laurel, for added measures I will make that a comment :D
 
ps.I will not be responsible for any harm that may come to you from following my advice, and side effects may include: angry fellow devs, angry emails, verbal abuse and physical altercations.
 
making dict, list and others without having to import the generic types at least made me want to type my code, wish Optional and Any also had some builtin (no imports)
 
You can at least replace Optional[T] since 3.10 by T | None.
 
7:19 AM
ok, that is definitely better
on second thoughts, why didnt they do that Union? would make more sense right? considering the set like nature?
 
sorry? I don't quite get the question.
 
let me rephrase, Union[int, str, float] means any of int str or float right? so couldnt this have been int | str | float?
as how the | would do union for sets
hopefully this was clear than my previous attempt at explaining
wait, it is a thing? int | str == typing.Union[int, str] according to python.org/dev/peps/pep-0604
I thought what MM mentioned only applied to Optional, ok, sorry for the confusion
 
7:52 AM
No worries. It isn't exactly obvious that Optional is just a Union.
 
 
1 hour later…
8:57 AM
cabbage
 
 
1 hour later…
10:24 AM
How would I write a docstring for this? For example:
class Nothing:
    def __init__(self) -> None:
        self.test = AnotherThing()

class AnotherThing:
    pass
I'm using Google Style, should it be

Attributes:
test (AnotherThing): An instance of AnotherThing.
 
 
1 hour later…
11:33 AM
Occasional cbg
 
@RoyalFrog I'm not sure what you're trying to document. the attribute "test"?
just in case you don't have it bookmarked: google style docstring examples
 
 
1 hour later…
12:38 PM
There is this guy who always plagiarizes my posts, here is one for 10k+ users
Not a character different :P
Someone upvoted...
 
1:03 PM
@Arne Yes actually, but test is an instance, so I'm guessing it should be test(AnotherThing), though I might be wrong.
 
I'm trying to make sense of what you're saying, but I'm not getting there. Is this what you want?
class Nothing:
    """Doesn't do anything.

    This class doesn't do anything at all, it's just used
    to demonstrate stuff.

    Attributes:
        test (AnotherThing): A test attribute of a specific
            custom type.
    """
    def __init__(self) -> None:
        self.test = AnotherThing()
Now that I've written it out - yes, what you want is test (AnotherThing) in the Attributes block. And of course it's an instance, everything in python is one.
 
1:34 PM
Yeah that's what I was looking for. It's kinda my first time writing a docstring for a class, I tried looking through different formats and even looked at various Python lib on how they wrote it. But the examples I've gotten usually go straight to the attributes, like name (str) and age (int). Anyways, it was what I was looking for and sorry that my question confuses you
 
no problem, happy to help =)
 
@U12-Forward it's probably your serial downvoter trolling you. Ignore and flag. And by "ignore" I also mean "don't complain here". Mods will fix it.
 
2:42 PM
The other day I was playing a metroidvanialike Astalon. Like many games of that genre, the world is full of locked doors and keys. I wondered how how hard it would be to prove that the player can't accidentally and permanently lock themselves out of a part of the map.
 
I'd link a TVTrope but that would hinder productivity all across the room
 
Perhaps you can model it as a graph problem. Each node is labeled with a number indicating the amount of keys you can collect in that region. Each edge is labeled with the number of keys you need to move between regions. Then you... Do something with spanning trees? I haven't thought very hard about it
I'm worried that there's an element of statefulness that you can't totally eliminate, because it's easy to draw a spanning tree whose node-labels-minus-edge-labels total is positive, but which doesn't represent a valid solution
 
@AndrasDeak "Astalon: Tears of the Earth is a Metroidvania developed by LABS Works and published by Dangen Entertainment." Yam!
 
Ex...explain
 
As a very simple example, Consider a map with two rooms, separated by a locked door, and there is one key in the room you don't start in. The only possible spanning tree is a simple line from one room to the other. The total number of keys minus the total number of doors is zero, so one might naively declare that the maze is solvable. But it clearly isn't.
 
2:49 PM
I meant Miyagi. Not sure how that reply applies to my message. (Just to be clear.)
 
I'm guessing he's quoting a part of the TV Tropes page for Astalon, and cursing his misfortune at falling into the TV Tropes vortex despite your efforts to prevent that
 
Hmm... perhaps
in that case I'll never get a reply this week
 
Astalon is intentionally designed as a cliche magnet homage to classic gothic platformers, so I imagine its trope page is hefty
 
Absolutely not. Nothing to see there. Don't go to TVTropes. Just… turn around and run in the other direction. Now. While you still can…
 
"You can't just make up the genre 'gothic platformer'", you hypothetically say. It's totally a real thing. There's Castlevania, and Ghosts 'N Goblins, and, uh, Castlevania II...
 
2:55 PM
OK, so I just meant "Unwinnable by Mistake" :P
 
I see I see
citeseerx.ist.psu.edu/viewdoc/… looks relevant to my interest, albeit with many more bells and whistles than I need
 
3:18 PM
Finally I can put my frustration with games into words. It was M,spointless |=¬AG(EFlose) all along!
 
"words"
 
I've decided that my doors-and-keys problem is solvable in a mere O(2^total_keys) time.
 
Superpolynomial scaling is technically super.
 
3:34 PM
Construct a metagraph representing all possible game states, identify which terminal states are "won" and "locked out", and recursively mark every nonterminal state as either "lockable" or "not lockable" based on whether you can get from that state to a lockable state
 
old low-value typo, pollutes searches actually about persistence stackoverflow.com/questions/580866/…
 
4:02 PM
Perhaps there are some optimizations that let you skip constructing the entire metagraph. A starting room with one million keys, and one hundred locked doors leading to a single dead-end room each, is trivially not lockable. Open the doors in whatever order you like, there's no way to run out of keys before you open every door. But my naive algorithm would need to emulate 2^100 game states to figure that out.
"Mark a node as non-lockable if the number of keys in inventory is greater than the total number of remaining locked doors in the entire map" would prune the possibility tree significantly in this case. Unclear to me how often that would be useful for real-world cases
In many games, there are exactly as many keys as locked doors, so this pruning would only occur when you're one room away from winning the game. Unexciting gains there.
 
If a node contains enough keys to unlock every door in that region, you can omit that node from the graph
 
I like it. Opportunities for divide-and-conquer.
 
4:27 PM
I'm going to dial back my assertion from "In many games, there are exactly as many keys as locked doors" to "there are approximately as many". I think if the values are exactly equal, then it's hard (impossible?) to design a branching map that never locks you out of anything. Putting in one extra key gives you a lot of breathing room.
I may need a more formal definition of "branching" there because it means something other than "at least one node has at least three edges"
 
 
1 hour later…
5:31 PM
can somebody check my last question?
 
5:42 PM
In the past when I was working with probabilities that got really small I hit underflow problems and had to convert my functions to operate in log space. Then at the end I converted back to non-log space
I have a huge JSON file--it's too big for main memory. It's a list of dictionaries / objects. Is there a ready-made way to get the keys with a streaming method?
 
json-stream seems to be exactly what you need
That's actually a really cool implementation. I thought a streaming parser would be much more inconvenient to use
 
6:30 PM
@AliAlCapone the room rules say to wait 48 hours before asking here
 
btw guys, which plotting/viz library gives you guys the least headache for making interactive things
 
Shower thought of the day: "ah", "eh", "oh" and "uh" are all onomatopoeias, but "ih" isn't
 
6:46 PM
eeh?
'ih' sort of sounds like it is very close to something like 'ikh'
 
7:11 PM
@tripleee Wow. 136k, all from questions.
 
long live the question rep recalculation
 
Yeah. That question isn't exactly a typo, but I suppose we can class it as "unlikely to help future readers".
 
7:27 PM
done
 
7:57 PM
cbg is there a way to make an in house Python framework configurable and modular
For example, Spring framework uses a bunch of annotations to assist with the dependency injection, configuration, etc.
I'd like to make something similar for an e2e testing framework where I can configure which tests to load, which dependencies each test has, etc.
Would that just be global cache I would add to?
For example:
@depends_on('test1')
@use_testfile('mytest.json')
def test_test2():
  pass
 
8:23 PM
NooooOOOOooooo. I just lost the Google Foobar challenge a second time :'( Why do they make the effect so damn slow while one is jumping between pages?
The first time it happened I thought I'd landed on a dodgy site, panicked, and clicked back immediately. Just now, I'd decided to switch my search term very quickly and had to watch the intro screen slowly unfold while the unstoppable new search was going through. Crushing. I'd really like to have a go just to know what it was like
 
8:41 PM
IMO it's a lot like those coding challenge websites. More about deciphering what the heck they want from you than actual coding
 
Have you actually managed to have a go?
 
I did like 2 levels and then dropped it when it stopped being trivially solveable
 
That's a shame. Is it just pain for pain's sake vs. something in a "real" context?
 
I think you should be able to log in if you visit foobar.withgoogle.com
 
LOL; I think I've already failed. I googled on how to get it back and found that link with people suggesting it wouldn't work - but clearly they hadn't been invited.
 
8:46 PM
@roganjosh Hmm. The context was some over-the-top fantasy rubbish, but that doesn't mean the problems didn't have any real-world applications. I honestly can't remember, it's been too long
 
Btw, it won't let me sign in. I think you really do have to snag the initial animation
 
lol
 
But given that it's Google and I'm signed in to my Google account when I got shown it.... seems a little short-sighted. Maybe I'm too erratic
 
@Aran-Fey you can delete that and only ROs could snag
 
high tech private messaging technology
 
8:48 PM
and mods I guess
and employees
...but other than them
I wouldn't be surprised if the invite link was also tied to an account
 
It isn't. I snagged it and I think it's tied to my Google account now. That was actually a really cool gesture @Aran-Fey, thank you
 
no problem, it's been sitting there unused for years
 
plot twist: it is tied to an account, and they will drop you in a chute at the last level for using someone else's invite (illustration: Grim Fandango spoiler)
 
Well, that's one way to dampen the mood :P
oh well, the dragon looks pretty cool, and I get to sip a martini before riding it. That's pretty cool, I guess
 
9:07 PM
Why won't print("\nHi".center(10)) centers the text, but removing \n does
 
This is probably useful
And indeed, you get the expected behaviour with:
my_str = "\nHi"
for line in my_str.split('\n'):
    print(line.center(10))
 
@RoyalFrog Well, it does created a centered string, but that string isn't what you're hoping for. The str.center method doesn't "know" what "\n" means, it's just another character. The call "\nHi".center(10) returns ' \nHi ' which is indeed centered.
 
>>> "\nHi".center(10) == '   \nHi    '
True
like that
 
You would see this with the following @RoyalFrog. I had a brain fart with my response to PM 2Ring's comment:
my_str = "\nHi"
print(repr(my_str.center(10)))
 
9:25 PM
I see, yeah I had to use f-string for that, didn't know the returned value is already centered. Thank you guys
 
I thought I had a nice answer on the main site about this, but I can't find it. But this one shows how to print a table with right-justified columns, and it's easy to modify it to do centered columns instead. stackoverflow.com/a/51937408/4014959
f-strings are good, and I generally use them these days, rather than the old justification & centering methods.
 

« first day (3981 days earlier)      last day (967 days later) »