« first day (4931 days earlier)      last day (14 days later) » 

12:47 AM
Hello, how do I error handle 403 requests? I have a discord bot with a ban command, and when banning a person, sometimes I receive a 403 that tells me the bot cannot message the user. I make the bot message the user before making the ban to let them aware that they are banned off of that server.
 
1:06 AM
@roganjosh To experienced programmers, it means "without importing non-standard or uncommon packages". Can be debated whether that includes/excludes numpy/scipy/et al. Sometiems you have to work with an install or VM which does not allow you abitrarily install packages. (I wonder if one upshot of the xz Tools exploit on security-conscious platforms will be "managed installs" locking down packages or package versions)
 
1:22 AM
I only recently found out that s[::-1] is unsafe for reversing strings with Unicode, should use reversed(s) instead. (using bytearrays is also a pitfall). KK's list of examples is useful. "🇬🇧 # "[::-1] yields "🇧🇬" because '🇬''🇧' gets flipped to '🇧''🇬'.
... And 'fiancée'[::-1] becomes 'éecnaif' (note the accent jumped one letter) if it was composed from the grapheme Unicode Character 'COMBINING ACUTE ACCENT' (U+0301) instead of the more common 'é': 'LATIN SMALL LETTER E WITH ACUTE'
But, lots of code assumes ASCII or left-to-right languages (or ASCII-hammered), and there's a lot of this sort of code on Leetcode-type platforms, where questions usually use only ASCII. So I think the missing phrased question is "Why is accessing/reversing/manipulating strings with s[::-1] or bytearray unsafe on non-ASCII strings?" Reactions?
There's also a missing link to advice on normalized Unicode, and do we have to keep the the non-normalized input representation, can we always throw it away?
 
1:42 AM
@smci If you ever have to care about Unicode things just get very buggy very quickly. I'd imagine bytearrays could be worse with UTF-8 data if you ever work with 16 bit characters, as the character is split across two bytes. Similar to combining characters.
 
^^ and the corresponding SO question How do I reverse a string in Python?
 
As in you don't even get correct Unicode characters back:
>>> "日".encode("utf-8")[::-1].decode("utf-8", errors="replace")
'���'
>>> "日"[::-1]
'日'
 
2:25 AM
@smci please also put something about this in python-canon-discussion if you haven't already
(also, using reversed doesn't fix the problem. you really need a grapheme-aware third-party library)
 
2:52 AM
@KarlKnechtel Equivalently, there's no solution using builtin Python libraries (when will grapheme become a builtin?) The phasring of the question is vague, since for better or worse, programmers in general associate string with "ASCII" and "Unicode" with Unicode, and even though Python 3.0 redefined string to not mean "bytes", most programmers aren't Python. So arguably the question title should say "How do I reverse a string which may contain Unicode, in Python?" Or else we need a new question...
...and in the question body state that [::-1] reverse-slicing, reversed(s) and so on are broken and give one-line examples why. The "correct" answer reversed_string = "".join(list(grapheme.graphemes(input_string))[::-1]) is beyond well-hidden.
@Peilonrayz Yes, bytearray is a trainwreck for accessing/manipulating string contents but lotta answers here still recommending them.
 
 
2 hours later…
4:30 AM
(well, there is if you write it yourself, but the code won't fit in a SO answer)
anyway, you get the sense of why I prefer the idea of starting over on Codidact.
 
4:44 AM
grapheme is not builtin. The non-builtin package regex also has grapheme support with \X... but is this output of regex.findall(r'\X', ...) guaranteed correct or not?
(I was composing an example but my terminal keeps messing it up)
 
5:21 AM
@smci I mean more in relation to the standard library. If anything, I find the dictionary counter method more "magical" than just using Counter
 
 
9 hours later…
2:20 PM
Good lord, 18 chat flags. New high score
 
3:16 PM
Has anyone tried out uv as a pip replacement? It's the first I have heard of it
 
from typing import Final
host: Final[str]
sep: Final[str]
port: Final[str]
#host = "localhost"
host, sep, port = "localhost:8808".partition(":")
Is this a bug in Pylance?
"sep" is declared as Final and cannot be reassigned
 
@matszwecja Probably. You can get the same issue with CONSTANTS:
FOO: str
FOO = ""
 
 
5 hours later…
8:38 PM
@roganjosh I stumbled over it from another Astral.sh project but haven't used it.
@matszwecja That's kind of the point, isn't it?
 
9:02 PM
That's the first assignment though
 
 
2 hours later…
11:15 PM
@roganjosh I agree that shoehorning a dictionary into a counter is suboptimal for general use; Hettinger does stuff like that as learning example to push people to ask how much functionality their use-case needs and can it be simplified. A Counter is a dictionary whose methods have been overloaded/augmented for proper Counter-like behavior, such as most_common(). Adding two Counters does the right thing. Whereas adding two dict-Counters is undefined. Adding a Counter to a dict gives a mess.
 

« first day (4931 days earlier)      last day (14 days later) »