« first day (4938 days earlier)      last day (10 days later) » 

7:12 AM
Best password policy I've ever seen:
> Password Policy: Use the whole keyboard
 
7:23 AM
I ran into issues with what seems like truncation issues and exceeding the maximum size sites allow for passwords... Also special characters can be a bit of a pain at times :/ But YMMV, I just lost lots of hope in most sites' security.
 
Same, especially when some sites enforce max 8 chars or don't let you use specific characters
 
 
5 hours later…
12:31 PM
I'm having a typing problem somewhat similar to this one again. I want to make a function decorator that only works on functions that accept an Image as the first argument. Last time I could use a TypeVar bounded on Callable[[int], None] because the 2nd parameter was optional, but this time the decorated function can have mandatory arguments after the Image
This time I'm out of luck, aren't I?
 
 
2 hours later…
2:41 PM
@Aran-Fey If you don't need the exact type you can paramspec it.
def display_image_on_error[**P, R](func: Callable[Concatenate[Image, P], R]) -> Callable[Concatenate[Image, P], R]:
    @functools.wraps(func)
    def wrapper(img: Image, *args: P.args, **kwargs: P.kwargs) -> R:
        ...
This will match all the use-cases in which a new wrapper is produced by the decorator.
 
@MisterMiyagi Do you typing people REALLY think this piece of code is a good idea? I mean this a horrible abomination and I really hope you wake up...
 
Hey, I'm not writing such code, let alone designing the typing spec...
 
@MisterMiyagi It's an impersonal you :)
 
Special forms like Callable and Concatenate should have syntax supports and that's it.
@Hakaishin [planet of the apes.gif]
@Aran-Fey Ooooh, turns out Concatenate is even... n̷̦̥̳̻̽̎̈̿ȋ̵͉̲͒̿c̷̹͎̀̍͆e̶͈̥̗̒̏̊͠ŗ̷̥̯̭̀̇̒̇ ... than I thought.
def display_image_on_error[F: Callable[Concatenate[Image, ...], Any]](func: F) -> F: ...
 
2:58 PM
@MisterMiyagi Thanks, that's... embarrassingly simple
 
wishes we had (Image, ...) -> Any
 
But I bring bad news: The problem got trickier in the meantime. The decorator should work on functions that accept either a PilImage or a NumpyImage as the first argument
 
Just union the shame out of it.
 
@Hakaishin I do. It's a tradeoff: The internals get messier, but the user interface gets nicer
 
Pro tip: Any enumerable typing problem can be solved via unions. 👍️
 
3:00 PM
@Aran-Fey I like global optimization. Would you say the cleanness outweighs the messiness if you don't weight the outside with more than 1?
 
@MisterMiyagi That doesn't work, a union means that it only works on functions that accept either
Overloads would work, I guess
@Hakaishin I don't know what that means. I do value the outside more than the inside, if that's what you're asking
 
@Aran-Fey I mean in your head you did a tradeoff and came to the conclusion that the messiness inside is worth it the cleanness of the interface, but you weighted the benefits and drawbacks differently. I'm asking if you would still say it's worth it if you value both sides with 1. Which in simpler terms you could say, if you would be producer and consumer of that software/interface, would you still do these type annotations?
 
@Aran-Fey You can union the functions instead of the arguments. 🙃
 
Isn't that a nonsensical question? If I weigh the benefits and drawbacks equally, then my answer is *shrug*
 
F: Callable[Concatenate[PilImage, ...], Any] | Callable[Concatenate[NumpyImage, ...], Any]
 
3:13 PM
In reality I am both producer and consumer, and I'm debating if the overloads are worth it. But only because this is a function that's solely used for debugging. (Which means that I'm the only consumer.)
 
@Aran-Fey not really. Say action x adds 10 messiness internally and adds 5 cleanness outside. Say you value inside at 0.5 and outside at 2 and say messiness/cleanness is the same scale so the equation would be should_i_do_it = 0.5*(-10)+2*5 = 5, positive values would mean yes, negative mean no. Now if you adjust both weights to 1 it would mean you should not do it
 
Fair enough, but I can't quantify it that accurately
@MisterMiyagi Am I doing something wrong? I need 3 # type: ignores with that approach
def display_image_on_error[F: Callable[Concatenate[PilImage, ...], object] | Callable[Concatenate[NumpyImage, ...], object]](func: F) -> F:
    @functools.wraps(func)  # type: ignore
    def wrapper(img: PilImage | NumpyImage, *args, **kwargs):
        try:
            return func(img, *args, **kwargs)  # type: ignore
        except Exception:
            img.show()
            raise

    return wrapper  # type: ignore
 
@Hakaishin I don't think it's as clear-cut. While writing types can be messy, that's something you do once and then that's it. But you'll get a benefit every time you work with them, both externally (for using the function/class) and internally (for refactoring).
@Aran-Fey Can I interest you in our lord and saviour, Any?
 
3:33 PM
Nay
 
4:09 PM
@MisterMiyagi haha putting any everywhere is suuuuch an improvement xD I will die on the no typing hill
 
you're welcome
 
4:41 PM
I had another crazy idea for a programming language: Overloading functions based on metadata. Meaning you can have different implementations for "large file" vs "small file", or "local file path" vs "network file path"
list.index automatically becomes log(N) if the list is sorted
 
Polars allows meta tags like set_sorted where you pinky promise to the implementation that you know it's sorted and you'll take any gremlins that come from the optimisations on the chin if you lied to it
 
Turns out it's a good thing if the machine has an understanding of what's going on in your code!
 
5:07 PM
I've only ever had to set a single column for this but now I look at the interface and it's confusing. "column -> Columns that are sorted. more_columns -> Additional columns that are sorted, specified as positional arguments." I wonder what the difference is between columns and more_columns
I guess the "s" just needs to be removed. Easy PR to get under one's belt :P
 
 
1 hour later…
6:28 PM
@Aran-Fey I don't have Python 12, but I'm pretty sure Callable[[PilImage], object] | Callable[[NumpyImage, object] can't be assigned to Callable[[PilImage | NumpyImage], object]. (What wrapper is) Because the function either takes PilImage or NumpyImage. Have you tried changing the F: to put the unison in the Concatenate?
Alternately you can overload if you do need the unison outside the Callable.
 
If F is bounded on Callable[[PilImage | NumpyImage], object] then the decorator can only be used on functions that can accept both a PilImage and a NumpyImage as input
You can play around with it on pyright-play.net
 
@Aran-Fey Ok, but I'm only trying to answer the question how to remove the three # type: ignores. Does the overload solution not solve the issue if you do need the unison outside the Callable?
 
6:47 PM
Yeah, it does
 
7:00 PM
I was just exploring other options for the sake of brevity and education
 
FWIW I'm starting to think typing the internals of decorator functions, among other things, is a colossal waste of time and using Any/# type: ignore is the best option.
 
Yeah, decorators get pretty ridiculous sometimes
 
7:35 PM
@Aran-Fey PyPy supports something technically similar. For example, if you have a dict with only str keys it uses a different implementation from the default. Likewise, a list with just floats is turned into an array[float] under the hood. You could have list.sort return a special type that knows it's sorted.
 

« first day (4938 days earlier)      last day (10 days later) »