this post was submitted on 16 Mar 2026
1 points (100.0% liked)

Python

7870 readers
1 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS
 

For example:

class FooBar:
    def __init__(self):
        self.a: int = None
        self.foo: str = None

Is this bad practice/go against PEP guidelines or is it fine?

you are viewing a single comment's thread
view the rest of the comments
[–] logging_strict@programming.dev 0 points 3 weeks ago (1 children)

dataclasses required py310+ for critical features like slot support. Only now that py39 is history, is dataclasses even a thing. But then a must have feature will require an even more recent python version. So stuck waiting in a never ending loop.

Fck that!

python -m pip install attrs

Problem solved.

[–] solrize@lemmy.ml 0 points 3 weeks ago (1 children)

I haven't needed slot support in dataclasses so far. It must not be that critical. Some of my machines still have python 3.9 and dataclasses work, at least to the extent I've needed them to.

[–] logging_strict@programming.dev 0 points 3 weeks ago (1 children)

That's fine. But you coulda had access to latest greatest updates. Whether you need them or not.

[–] solrize@lemmy.ml 0 points 3 weeks ago (1 children)

Python advertises itself as being mature, which means changes if any are supposed to be incremental and backwards compatible. It's not so successful at that but I still don't particularly try to keep up with the bleeding edge. I don't know what slots in dataclasses even means. I do like the match statement.

[–] logging_strict@programming.dev 0 points 3 weeks ago (1 children)

LOL have never used the match statement. Has been one of those features just outta reach. So close can taste it. But alas ....

Now py310 is here. Still not enthusiastic about it. But over time maybe will come around.

__slots__ = (...) or frozen. Same thing. Make the data class read-only reducing memory usage by 30-40%. Like the memory usage difference between tuple and list.

From experience, in stubs, __slots__ need to include "__weakref__". If frozen, then don't include "__weakref__".

How about this. Lets meet each other half way.

I'll stop thinking of the match statement as thorium reactor toxic waste.

And maybe you can take a read through of the frozen option for dataclasses.

Sound fair?

[–] solrize@lemmy.ml 0 points 3 weeks ago

If I need something like slots I'll keep them in mind. Thanks for calling my attention to them.