« first day (3795 days earlier)      last day (1136 days later) » 

2:20 AM
Ick! I'm installing the latest version of gimp (released Feb 2020) and watching it put a vendored version of python 2.7 on my system!
Well, after starting it, the first thing it does is tell me there's a more recent version, from Oct 2020. Uninstalled the old, installed the latest - still getting Python 2.7. Well, at least it is buried inside the gimp lib directories.
Sounds like it would be a worthy open source project to contribute to.
 
2:44 AM
One thing though, they have really optimized the startup time!
 
 
8 hours later…
10:40 AM
@PaulMcG so glad that googling "gimp" brings up a page of only GNU Image Manipulation Program-related results and not something NSFW
 
@aneroid like the basement scene from Pulp Fiction or something :p
 
@JonClements precisely! ;-)
 
11:05 AM
@AndrasDeak some of those less readable options are also much much slower. disclaimer, I'm on a slow machine. for ~44,000 dates:
%timeit [dt.datetime.strftime(dt.datetime.strptime(d, '%Y%m%d'), '%Y-%m-%d') for d in ds]
1.03 s ± 13 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit ['-'.join([d[:4], d[4:6], d[-2:]]) for d in ds]
22.3 ms ± 540 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
%timeit [f'{d[:4]}-{d[4:6]}-{d[-2:]}' for d in ds]
19.9 ms ± 992 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
 
@aneroid we're talking about formatting an 8-length string. Speed is irrelevant.
 
so if it was much longer (1K chars), then slicing would be really bad...?
just meant - the more readable option also has the benefit of being faster
ok, repeated slices vs nested calls with a format string '%Y-%m-%d' - potayto potahto
 
11:32 AM
FWIW, without having read your previous description, the fast solutions wouldn't make any sense to me.
 
Hello, good day guys. Can I check whether there is a way in Python to simulate click/drag events in a window, without have to move the cursor? Basically I want Python to perform some clicks without actually taking control of my mouse.
I am checking on the win32gui below functions:
win32gui.SendMessage(hwnd, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, lParam)
win32gui.SendMessage(hwnd, win32con.WM_DROPFILES, win32con.MK_LBUTTON, lParam)
win32gui.SendMessage(hwnd, win32con.WM_LBUTTONUP, 0, lParam)
 
11:49 AM
Hey guys when trying to document your function is it good practice to use : on the args to state the type expected? i.e. def func(a: str, b: list, c: int):
 
You can either document the types like that, or in the function's docstring. Your choice
 
Using proper type hints has the benefit that it's much easier to start type checking should you ever need to.
 
12:05 PM
@MisterMiyagi fair enough. but that'd be true for all string slicing, right? regex's with named groups may be more readable, but overkill.
here's another terrible option, trying not to rube goldberg it but it's tempting:
[[(i:=int(d)), f'{(y:=int(d) // 10_000)}-{(m:=i // 100 % y):0>2}-{i % 100:02}'][-1] for d in ds][210:220]
71.9 ms ± 3.73 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
 
Revisiting co- and contravariance again because I realized I still don't understand it. As far as I can tell, variance is only a thing when you're comparing types? For example, a List[bool] is not a subtype of List[int] because lists are invariant. (Is that even correct? Shouldn't we say "the elements of a list are invariant"?) But simultaneously, you can still assign the list [True, False] to a variable that's of the type List[int], because booleans are integers.
In other words, [True, False] is not inherently of the type List[bool]. You can treat it as a List[int] if you want
My respect for the folks who wrote mypy is skyrocketing
 
12:24 PM
@aneroid no, I'm just saying that I didn't even look at your timings because only readability counts here
 
@AndrasDeak ah, I see. makes sense now
don't read my most recent option then ;-)
 
@Aran-Fey Variance only occurs for generic types + subtyping. int by itself does not have variance; the T in List[T] has variance, and int happens to be assigned to it.
Assigning a: List[int] with some List[bool] is not correct, because it allows to silently pollute the List[bool] with integers.
The important question is whether you ever have a separate reference to the list as a List[bool] – if yes, promoting it is wrong, if not, promoting it is a victimless crime.
 
1:31 PM
recbg
@Aran-Fey you could read some Java articles about this; also, I like the Java syntax more
so in Java terms covariance you would write list<? extends int> and contravariance as list<? super int>
@Aran-Fey this parametrizes the type of the list, so that the list is of type list<x> where x either extends int or is a superclass of int... a list<bool> is of course of <? extends int> too... but it itself is not a list<int> because they are just type parameters not of type hierarchy...
 
 
2 hours later…
3:16 PM
Alright. Another thing I'm confused about are TypeVars. It seems to me that TypeVars have two completely distinct purposes depending on the context they're used in. If used to parametrize Generic, like for example in class MyList(Generic[T]):, the only thing that matters is its variance.
On the other hand, if used anywhere else, the variance is completely ignored - for example, x: Tuple[T, T] means "x is a tuple with two elements of the same type". T's variance is completely irrelevant there, right?
In other words, when used with Generic, TypeVars specify the sub-type's variance, and everywhere else TypeVars simply link the types of 2 different things
 
3:46 PM
IMO that's the same as regular variables: You can declare/create them (a=b, Generic[T]) and use them (a*2, x: Tuple[T, T]).
 
Hmm, I can't say that clicks for me :(
But it's good to know that I didn't misunderstand anything
 
4:35 PM
@Aran-Fey well ... yeah basically Python made an ugly syntax for something that looks so much nicer in other languages...
in Java you declare the scope of the type variable by introducing it lexically:
class Foo<T> {} - and within that body T will refer to the same T thing all the time. OTOH, since Java is compile-time only, you will *never have Pair<T, T> x without knowing what T is bound to - it is either the type of the method parameter or type of the class template parameter.
so if you look at:
T = TypeVar('T', int, float, complex)
Vec = Iterable[tuple[T, T]]

def inproduct(v: Vec[T]) -> T: # Same as Iterable[tuple[T, T]]
    return sum(x*y for x, y in v)
 
Yeah, in Java it's much easier to grok, since you can't re-use the same TypeVar for multiple classes, and you can only set its variance in places where it makes sense
 
4:50 PM
The entire “creating typevars” thing is very unfortunate, variance in specific. Logically, the variance is determined by the scope instead of the variable.
Never understood why they didn’t at least go for a “typevar namespace” to create vars, and perhaps operators for variance.
So one would do class Foo(Generic[+K, -V]):, for example.
 
That would've been much nicer, yeah
Also, this error message is pretty rich:
>>> TypeVar('T', covariant=True, contravariant=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/typing.py", line 609, in __init__
    raise ValueError("Bivariant types are not supported.")
ValueError: Bivariant types are not supported.
What's "supported" even supposed to mean, python itself doesn't even do anything with the variance
 
5:08 PM
Of course, your Google search results will take into account your previous search term history, so your results may not be the same as those of others (like @JonClements, possibly).

Just sayin'.
@ParitoshSingh I just said this the other day on company Slack, when they gave me privs to deploy to production.
 
 
1 hour later…
6:18 PM
@PaulMcG well, I can't comment on @JonClements' search history ;-) but... just checked and... even in Private window/incognito mode, all of the first page is about the image tool and not the "suit"
 
 
1 hour later…
7:31 PM
Is there a term for things that have a __module__ and __qualname__? (So basically classes and functions)
 
8:14 PM
In a library I published on pypi I abbreviated "parameter" as "param" a lot. On a scale of 0 to 10, how bad of an idea would it be to deprecate a param_list property and a bunch of param_type parameters in favor of parameter_list and parameter_type?
 
For aesthetics? And what is the version of your library?
It might make a difference if it's 0.0.1 or something larger :P
 
8:31 PM
I prefer param_list over parameter_list. hopefully it's not confused for a "list parameter" :-/ so..imho, params > param_list > parameter_list - not for the abbreviation but because even verbally it's said that way (by many). not a fan of lst to name arbitrary lists
 
@AndrasDeak Yeah, no real reason. I just found myself writing foo.parameter_list and wondering why it threw an attribute error, only to discover that past me named it param_list.
It's version 1.1 at the moment... would jump to 2.0 when the old names are removed
@aneroid The thing is, there already is a parameters attribute which is an OrderedDict. So I definitely want to have "list" in there somewhere to clearly distinguish it from the dict version
Why do you prefer param_list? Just because it's shorter?
 
@Aran-Fey between param_list and parameter_list - yes. but especially in this case coz we say and write params so naturally
same reason I would write dicts_list or dict_list and not dictionary_list (bad example, but we can have lists of dicts. see! i did it without thinking)
in general I'm not a fan of super short variables if they lose context/meaning. only reasonable exceptions are comprehensions and c for counter or i, j, k for immediate nested loops. I've even started using idx for index instead of just i
 
8:46 PM
Hmm, you have a point. But I just noticed I've committed the sin I hate the most - internal inconsistency. I already have a bunch of parameters and functions with "parameter" spelled out, so it's easier to turn the few "params" I have here and there into "parameter" than the other way round
 
agreed on that - you'd be changing fewer things (majority wins)
 
I have a 2 dimensional array of class objects of the same class:
my_classes = np.array([[MyClass(), MyClass()],
                       [MyClass(), MyClass()]])
I want to map each value of a new array (with the same shape as the array of classes) to each number attribute in the array of classes.
My attempt (Obviously, I'm a beginner in numpy.):
while True:
    numbers = np.array([[new_number(), new_number()],
                        [new_number(), new_number()]])
    my_classes[:,:].number = numbers
 
Why do you have custom objects in a numpy array?
 
Can I get some help?
@roganjosh Pygame + cv2
 
But it might as well just be a nested list
 
8:48 PM
Oh, that's way too slow...
 
Your approach won't be any faster
Did you check the dtype of your resulting array?
 
Strange...
@roganjosh umm, ndarray?
 
It's not strange at all. You can't just view numpy as lists on steroids; they can only work on a subset of objects. When I said dtype I meant print(my_classes.dtype)
 
I don't understand your call new_number(), is that some custom class? What is it?
 
It's supposed to represent a value that changes
@roganjosh Oh, thanks for the info!
But I'm still curious. So it's not possible to update an attribute of each class in an array without iterating through the array to access the classes, right?
 
9:07 PM
@AnnZen no
Numpy arrays barely work with generic objects. They are designed to be used with native numpy types (i.e. numbers). That's when numpy is memory-efficient and fast. With object-arrays it's neither.
 
@AndrasDeak Oh, thanks!
 
 
1 hour later…
10:33 PM
recbg
 
11:31 PM
is it possible to @ mention someone in a comment if they haven't posted a comment themselves? in this case I'm trying to @ a person who posted an edit to an answer - while "an improvement", it's different from the answerer's intent
 
@AndrasDeak thanks! that's exactly what I was looking for
 

« first day (3795 days earlier)      last day (1136 days later) »