« first day (4731 days earlier)      last day (348 days later) » 

12:44 AM
@RyanM well, yes. same idea as not declaring instance attributes within the class body
constructors have the same syntax as ordinary methods; therefore, they behave the same way, too.
 
5 hours later…
5:46 AM
Ehhhh I'd argue constructors arguably use different syntax, in that they're typically invoked with ClassName(...) instead of method_name(...)
(you can invoke __init__ manually, but you typically don't)
6:37 AM
Tbf __init__ on its own is not a constructor
It doesn't create new instance of an object
6:59 AM
I don't like the distinction between "constructor" and "initializer". If you create an object without calling its __init__, chances are it's missing a bunch of instance attributes and will throw an error as soon as you try to do anything with it. Sure, technically you've created an instance of the class, but if you can't use it as a duck, is it really a duck?
Hmmm. It's early in the morning and CPython is already drunk.
>>> re.Pattern.__new__(re.Pattern)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object.__new__(re.Pattern) is not safe, use re.Pattern.__new__()
@Aran-Fey I agree, but that's kinda opposite of what I was saying; __init__ is not a constructor and __new__ is not initializer. MyClass() is both.
Sometimes you need to make a distinction between those 2 processes.
Just calling a constructor is kinda an egg of a duck. It's not a duck yet, but it has potential to become one.
7:30 AM
@RyanM oh, I meant within the class body :)
in Java, you can make a distinction because there's a spot in the grammar where there would normally be a return type, that is now omitted.
@Aran-Fey this is a fun one; I'm pretty sure I could explain it with a bit of effort
@RyanM Perhaps it helps to remember __init__ and __new__ are just hooks of calling type, same as __add__ isn't the + operator but used by it. In Python you don't call the constructor intentionally, and ClassName(...) isn't some blessed constructor syntax.
@Aran-Fey IMO the distinction helps when people want to construct something else and wonder why __init__ can't do that. It... happens...
@Aran-Fey I'm using pytest-asyncio or a self-written decorator that just forwards arguments and calls asyncio.run. Not sure why this needs a plugin, TBH.
@matszwecja True, sometimes you do. But I see too many people doing it anytime someone calls __init__ a constructor
7:46 AM
Well, all those pitchtorches aren't going to angrily shake themselves...
@KarlKnechtel Give it a shot, because this is leaving me baffled.
yeah but see, it's effort that involves looking at a bit of source and reminding myself of a couple of things, and I should be sleeping instead :)
@MisterMiyagi Having a timeout is pretty nice... as long as it doesn't interfere with debugging
And I don't wanna have to add a decorator to every test, yuck
Great, this has no timeout and Ctrl+C doesn't do anything. Awesome
 
1 hour later…
9:17 AM
@Aran-Fey Ah, guess I'm used to taking this differently since I'm still used to having different event loop libraries.
Admittedly, I'm still getting used to asyncio-only. But so far it's working well indeed.
https://stackoverflow.com/questions/77200794/use-match-case-to-handle-exceptions
Thinking of this question, what do you think of such function:
def handle_exception(exception: Exception):
    try:
        raise exception
    except (TypeError, ValueError):
        pass
    except Exception:
        pass
is try: raise dirty code?
this looks a bit pointless to be honest.
oh, you just want to match them.
Use isinstance for that, that's what except does.
I've only ever needed try: raise when stitching exceptions, and I've only ever needed that for a custom ExistStack.
9:33 AM
Umm... looking at that Q... especially as they're custom exceptions - why wouldn't you just have the thing raising the exception define the message...
@matszwecja Your answer could be improved by showing the equivalent of case MyCustomExceptionOne() | MyCustomExceptionTwo() since the naive equivalent – using multiple isinstances – isn't the proper way to go.
But overall I feel we are looking at an XY problem here.
In [1]: try:
   ...:     raise Exception('I like cabbage')
   ...: except Exception as e:
   ...:     print(e.args)
   ...:
('I like cabbage',)
 
3 hours later…
12:15 PM
@roganjosh there is a setting, poetry config installer.max-workers 10, they just use os.cpu_count() for the default: python-poetry.org/docs/configuration/#installermax-workers
I found it two messages later :)
I really don't get why people insist to default on grabbing ALL ZE CORES for every trivial task. ;_;
I even saw that message, but for some reason felt so absolutely certain that you were answering miyagi that I didn't even check the link ._.
From the previous discussion to that point, I'm not sure switching from os to psutil for the default count will help with k8s, but it might help with other methods of carving up instances
For example, just running a single Docker container in an instance, which you have deliberately restricted resources to. That's still going to go bonkers if you allocate 2 CPUs on a 64 core machine
Some sane default such as "4" could be enough. That shouldn't choke a 1-core allocation, still reasonably scale up on many core allocations, and not be entirely wasteful for tons of cpus.
Logarithmic scaling with number of cores also works rather well to avoid explosions from misdetecting the count.
12:31 PM
What would that look like for poetry? It'd have to be a rapid feedback loop for it to scale in a meaningful way when it's just pulling dependencies. For that application, I think your "default of 4" makes most sense, and then people can scale it up if/when they become aware of the env var vs. watching it go boom by default and then have to find that particular setting
Something like math.log2(os.cpu_count()) will scale very gracefully. But yeah, it's basically a fancy way to say "about 3 to 4".
Ah sorry, I interpreted is as your program thinking "well 4 cores just worked fine, let's up it" during a single run. Something like a reverse backoff with a 360 twist and nailing the landing :P
I'm a big fan of using feedback loops for this kind of thing, but usually the overhead just isn't worth it.
 
3 hours later…
3:17 PM
I'm bored and checking out other programming languages. Any recommendations for something that's similar but preferably faster than python and doesn't have problems with circular imports?
I tried out nim recently, but the only pythonic thing about it was the syntax
Rust feels surprisingly familiar to Python, but not sure if it matches your needs...
Have you given Julia a try?
Not sure about their import system, though.
I thought Julia was tailored specifically for data science? I guess I'll take a look
They have some odds and ends that make it most suitable for data science but it's general purpose and has everything you need for, say, automation and other tasks that Python is used for.
Rust is too low level for me. It's a step up from C, but ultimately still too fussy about the details
That's really the same problem I had with nim, like, I can't even add an int and a float? C'mon
That means Golang is right out as well, I take it.
You can always try PERL or whatever it is called these days...
3:25 PM
I have a faint dislike for Go, but I hardly know anything about it. I'll check it out
I have a strong dislike for Go in case that helps your decision. :P
I trust your judgment. But it's not like I have anything to do, so...
For reference, the current top contender is Typescript. The biggest turnoff is that there are some surprisingly big holes in its type system. (A method that returns -> Self? Almost impossible in TS)
Gonna love Golang, then. :)
Either my sarcasm detector is broken or my antenna is receiving mixed signals
3:56 PM
Have you had a go with cython or is that insufficiently different?
That would give you a decent shot with extensions. Or maybe React Native if you're thinking of a JS slant since that would give you mobile app capabilities
Kotlin also has a shot at app dev, but I lost interest because I didn't have an immediate project to help with. Still, the language is a good improvement over Java imho
Hmm. Maybe I should feel more excited about Cython, but it kind of feels tacked on. It doesn't solve my circular import troubles, for instance
Or does it? Now that I think about it, it actually might
I can't answer about unknown circular imports but it might if your extension is compiled down
4:13 PM
Thinking of Cython, perhaps MyPyC scratches most of your itches.
4:35 PM
I think I'd prefer something that's separate from python. Although python's type system is surprisingly good, it still causes issues (like circular imports) that simply aren't present in languages that were designed with static typing in mind. And the same thing goes for asyncio
Well, I guess as far as asyncio goes, there weren't many languages that had it from the very beginning. But most still pulled it off better than python did
I know I'm basically looking for the ideal programming language, but 1) Rust proved that miracles can happen, 2) A man can dream and 3) I'm trying really hard to avoid adding "create a programming language" to my todo list
You don't have AranLang on your Todo list? D:
<approaches tentatively with a shield ready to protect my face> is it really that important to have strict typing?
Typing causes me literally no issues that I can think of in python
4:51 PM
Anyways, I'm not aware of any real contender to Python in that regard. Most of the hard work seems to go into compiled/"proper" languages, leaving the practical stuff to the practically minded people.
@roganjosh Typing or lack of typing?
Any. You spend more time pontificating about how to properly type something than I do debugging me, myself, doing something dumb. But that's me
If I get properly confused about why something I think should work but doesn't, I honestly pay zero regard to the function signature argument in terms of expected types. I just look at the logic in the function itself
Hmm. That's kind of a tough question. I guess the core of the problem is that even simple type annotations can cause issues in python, namely circular imports. So while it's arguably true that I invest too much effort into typing, investing less effort wouldn't solve my problem
And I do want to have at least simple type annotations in my code. That part's non-negotiable
I'm wondering whether that's a code style thing? I practically never have circular imports due to types.
To be clear, I don't mean it as a criticism. I'm just telling you my own behaviour, for whatever that's worth. I've never run mypy once
4:58 PM
Neither have I (:
Err, I've never run something something to check my type annotations were accurate
Hopefully I recovered well there :P
My point was that the IDE checks it on-the-fly. It's much more convenient than an external tool
But yeah, I do see where you're coming from. Typing is a surprisingly large time sink
(To be more accurate, learning and familiarizing yourself with it is)
Can you demo this in Vscode with a tiny example beyond basic types? I'm genuinely curious about what autocomplete can't do unless you get really meticulous
5:17 PM
Sure, but I'm not at home rn, so it'll have to wait an hour or so
I look forward to it :) perhaps you can make me a convert!
You mean a cast ;P
Ooo, you didn't tell me there was an exclusive group to be part of!
 
2 hours later…
6:57 PM
I'm struggling to find an example that's both interesting and small...
7:12 PM
Let's say you have a function that returns a generator. You want to be able to use the generator in a with statement so that it's reliably closed even if the iteration is interrupted partway. So you write a function decorator that turns a -> Generator[T, Any, Any] function into a -> ContextGenerator[T] function. That's... slightly involved :D
I guess ints aren't the best type to test autocompletion on. But you can type i. and it should suggest as_integer_ratio(), to_bytes(), from_bytes(), etc
8:14 PM
@lengthylyova you will, of course, have read the room rules before posting here, noting the 48 hour waiting period

« first day (4731 days earlier)      last day (348 days later) »