« first day (4429 days earlier)      last day (502 days later) » 

Happy Advent of Code!
 
Ah, that time of the year again :)
 
5:49 AM
hey all, how can I stop mypy from complaining here sum(map(sum, [[1], [2]]))
that is the code, just one line and mypy throws two lines of error
other than # type: ignore
 
6:40 AM
@PM2Ring thank you for your feedback, glad to see I'm not crazy to think it's an abuse
 
managed to make the "grab dependencies for function" slightly better: gist.github.com/secemp9/3a30ccd9718ee88abbedf4ab1ed24b65 (using ast + inspect instead of string matching and locals() now)
it's still WIP though
 
7:36 AM
If I ask somebody did you do A and they respond with "Hi. Ok." What does that imply to you? they did it or they are going to do it?
 
@Hakaishin it implies that I'm not sure whether they did it or not
 
The speaker is french, I wonder if he incorrectly translated oui with ok
 
I speak French...I don't think that's how it's supposed to work (at least I never saw anyone who used it for that yet)
 
8:14 AM
@Hakaishin You should ask them again before things get lost in translation.
 
@MisterMiyagi It's a week past, it just jumped to my eye
 
@Jake Don't use sum to join lists. It's not intended for that and thus the type hints don't reflect that.
Wait, that's not what the code is doing, is it?
This seems to be a bug with MyPy's inference. You may indeed want to # type: ignore it for now.
 
8:30 AM
Well that's going to be a long-lived # type: ignore
 
yeah...
 
9:13 AM
Hmm doing a refactor I just realized why I intuitively preferred passing arguments by order and not by name. Now when refactoring an argument name, I have to track down all the usages of it. Especially if they are not in only one project
 
How to resolve : RuntimeError: Working outside of request context.

I've tried adding with app.app_context():
 
please provide more code
 
@matszwecja https://stackoverflow.com/questions/74600534/python-unittest-how-to-use-method-logic-for-unittest-in-python

This is what I've tried
@matszwecja In test file error arises in this line ....response =user_register()
 
9:29 AM
Does anything in here help? https://stackoverflow.com/questions/17375340/testing-code-that-requires-a-flask-app-or-request-context

Especially .test_request_context() seems worth a shot
 
Since I've used
def setUp(self):
      self.app = create_app()

        self.appctx = self.app.app_context()

        self.appctx.push()
still it is giving me this error
@matszwecja
 
but it seems like you need request context not app context
As the error says
 
Ok I'll try to add that one too
 
10:27 AM
@MisterMiyagi you might have figured, the actual use case is doing a flattened sum of 2d list
 
@Jake As a practical alternative, use a comprehension.
 
Practical and readable alternative
 
sum(sum(row) for row in [[1], [2]]) is no problem for MyPy.
 
yeah, the lambda alternative in the link you posted is just not doing it for me, it works, but I usually use map for default functions, which defeats the purpose here
 
indeed, it's not annoying when such basic things don't work well.
 
10:34 AM
I guess its time to jump to pylance(pyright), mypy just does not seem to fix these issues, I still see the recursive type issue open
no way, they closed it 2 days back
 
 
5 hours later…
4:01 PM
Anyone good with Tensorflow? I'm trying to gauge whether this answer makes any sense. The bad grammar isn't helping.
 
TBH I'm not even sure what the question is. No idea whether the answer addresses it, but it certainly makes up a lot of stuff.
 
That's what I suspected. Thanks.
 
 
1 hour later…
5:29 PM
How would I type hint a "1-dimensional number" (or in other words, a number that supports < and >)? numbers.Number doesn't support ordering, and decimal.Decimal isn't a numbers.Real.
Maybe I'll just go for Real | Decimal...
 
wait, it isn't? lovely
but yeah, the more I hear questions like this about typing, the better I feel about mostly ignoring it
 
I'm still unsure if typing is really a pointless time sink or if I'm just doing it wrong
 
I mean, just looking at github issues where a lot of people get stuck into not-yet-supported features, or bugs because of type hinting, I'm pretty sure you're not doing it wrong, so I don't think it's your fault
 
Oh, now you can't do Point(1, 2).x.to_bytes() because the type checker doesn't realize x is an int. Lovely. Let me add more typevars to my code...
 
I don't know if it's a pointless time sink, but I do know that it's a time sink. Just like anything else that take time to get right I guess
 
5:42 PM
it's the expected consequence of nailing a new type system onto something not designed for it. See also: Java generics. More broadly, see the entirety of C++ "design"
 
I feel like it's not so much that it's not designed for it that's the problem, it's that people who add features or plan on adding features don't take into account the future part/consequences
 
(although Java didn't actually turn out that badly, it's just that the wildcard system confuses people who want to use types without actually understanding any type theory)
 
if you add support for something and it break one thing, or you plan on implementing x,y,z but then forget to do it, it's not the fault of the language then
 
the future is inherently unpredictable.
 
that depends
 
5:47 PM
The future will be more declarative, mark my words
 
declarative programming, uh. didn't know that one
 
6:02 PM
Even floats aren't Reals, apparently
 
What.
(I think there might be something you need to import in order to monkeypatch the ABCs?)
 
6:19 PM
Googling tells me nothing, which probably means that nobody uses the numbers module
...and I guess now I know why
 
I know that numeric types are really complicated, but... error: Unsupported left operand type for < ("Number") is just flat wat
 
stackoverflow.com/questions/74646592 any experts around? I'm sure this is a duplicate
 
As the name suggests, things would be simpler without complex numbers
 
something about how the threads work and what calls are blocking
@MisterMiyagi well, yes; complex numbers are numbers, and can't be compared that way
 
Right, they are. Unfortunate...
There are some writeups on "how to type hint numbers" in this Q&A: stackoverflow.com/questions/69334475/…
 
6:45 PM
stackoverflow.com/questions/74646662 anyone know where the underlying homework question comes from? I have seen the example setup so many times now
 
TLDR: If float isn't enough, use Unions and type vars.
 
What even is a number anyway
 
anyway, I think we need a general canonical for running sum/max/etc. (i.e., accumulator in a loop) algorithms
I see wjandrea tried to respond there. The problem is that an OP like this certainly thinks that "can't find a way to make the numbers add up" is as specific as problems get
 
@NordineLotfi Interesting. And open since 2017...
> Not sure we need to keep this open, if it can be fixed in typeshed once protocols land.
- Guido, in 2017
 
peps.python.org/pep-3141/#numeric-classes indicates that the Number class has no abstract methods. So the only thing we can say about numbers for sure is: a number is an object.
en.wikipedia.org/wiki/Number#Main_classification is bold enough to describe a number as a "mathematical object", but that's subjective IMO
I'm a bit surprised that Number doesn't at least declare __add__. I don't know of any kind of number that can't be added to other numbers of the same kind.
 
6:57 PM
Abstract methods or not, Number is (or rather, would be...) still a useful type annotation because all the classes I care about inherit from it
 
1j + 1j is valid, for instance
 
(for some definitions of "inherit")
 
I accept your atypical definition of inherit
Thesis: strings are numbers because you can add them together
"I" + "II" == "III", that's unary right there
 
@Aran-Fey yeah, and sadly this isn't the only one either. Anyway, I don't know if you saw this: github.com/python/mypy/issues/3186#issuecomment-1200238263 might or might not be a viable temporary solution
 
So then iii is a lowercase 3, ||| is 3 with bad handwriting, and I I is... 2.5?
 
7:03 PM
there also this. Looks like either from a fork or a pull request that's not being merged.
 
@Aran-Fey ... I retract my thesis
 
Wise choice
 
that reminds me, unary encoding is a thing too. Many people implement it in their own way though, some use binary, other use a specific byte/char repeated the same number of times as their decimal representation, etc
 
did someone make a aoc lb here this year again
 
@12944qwerty I know what aoc is, but what do you mean by "lb"?
 
7:11 PM
leaderboard
 
ah, got you
I don't know if they do this on the aoc room, but maybe you could look there too
 
There's an aoc room?!
wow never knew
never mind I did know, I forgot. I have sent messages there too lol
 
@Kevin it's the first time I see you retract a statement :O
@12944qwerty maybe click on "toggle this as a favorite room" so you don't forget :)
 
ngl, I didn't bother looking for a room. I thought we just discussed everything in this room (or your respective language's room) instead
I completely forgot other rooms could exist
 
I noticed most people on the aoc room are using Python though (some there aren't usually in this room), so I'm not sure what to think of it
@12944qwerty it's still discussed here as you know, but it's not the main focus (compared to the other room that is)
 
7:19 PM
Python is probably the easiest to use for most challenges though
 
@Kevin nevermind, you used the word more than I could count, I retract my last statement too
@12944qwerty true
 
The AOC room is basically all python because it's run as part of our community. I don't think they'd mind other languages but wim was a regular here for many years and it's usually his initiative
 
@Aran-Fey just use object, then. :P
 
Ah, I see I omitted an important part... which is that classes I don't care about don't inherit from it :P
In other news, I just found myself doing the numpy equivalent of return True if x else False:
result = np.zeros_like(fg_mask, dtype=np.bool8)
result[fg_mask] = True
return result
 
@roganjosh noticed the same thing too yeah
 
 
1 hour later…
8:37 PM
does anyone proficient in classes know how I could avoid using self everywhere when using a variable inside a class? Just playing around with this: gist.github.com/secemp9/af4a5e433f957907ea0298a087bb3987
want to still be able to change and use the variable to_modify without having to use self on it, etc
I'm aware this is the recommended thing to do (and also probably default) but again, I'm just playing around, so don't mind if there a solution (even if it's non-recommended)
 
answer 1. use self everywhere. answer 2. assign the to_modify = self.to_modify in the function body. answer 3. just do answer 1. :P
 
alright :) I wouldn't do this for a serious thing though (eg: package, etc). Just playing with classes since I don't use them often
 
8:55 PM
Option 4: Magic!
 
no, dang it, bad aran, shoo!
 
I did think of inspect, but the way I would have done it would probably break. Thanks Aran :D
 
*hisss*
 
don't worry, I promise to not actually use this for serious project that any other potential humans will use (beside me)
 
It was only a matter of time, it's funny because I'm not even surprised, just amused
 
8:58 PM
You know it's not serious code because I didn't even copy the docstring and annotations and it explodes if the function is decorated
 
I see. Good thing I don't usually use decorators then :P
 
9:32 PM
@Aran-Fey explosions could be considered an extreme form of decoration. People will certainly say "I can definitely see you've done something with this place"
 
Might upset the neighbors a little bit though
Unless it's new year's
 
just give them a free decoration too
that will stop the complains
 
9:48 PM
@Aran-Fey do you have a reason not to use dtype=bool?
 
No, that's just because I don't know what I'm doing
 
and isn't fg_mask already a bool array?
 
Yes, yes it is
 
or is that precisely your point
 
See above (:
 
9:50 PM
It wasn't clear at first because sometimes you really need bool(x), and that doesn't work in numpy :P
 
10:44 PM
@Aran-Fey hmm, I just tested on 3.8 but receive an AttributeError: 'function' object has no attribute 'builtins' error. (this is with the pastebin's code, unaltered).
 
Change it to vars(obj.__globals__['__builtins__'])
 
yep, works :o Thank you
 
When/If it stops working, remove the vars
 
ah, yeah I see what you mean
 
10:59 PM
stackoverflow.com/questions/74649068 I acted too hastily on this because of the title; it should instead be a duplicate of stackoverflow.com/questions/6260089
 
11:20 PM
cabbage
what happens with dataclass
field(default_fact...)
vs something like
Optional[x]=None
if I understand correctly - it's a little annoying having so many variants (indecision on the direction forward?) to handle datatype unions.
 

« first day (4429 days earlier)      last day (502 days later) »