104 questions
4 votes
3 answers
180 views
What happens if __del__ is defined as an async def coroutine in Python (CPython 3.12)?
I'm experimenting with asynchronous patterns in Python and was curious what happens if I define a __del__ method using async def in Python 3.12. For example: class MyClass: async def __del__(self):...
2 votes
1 answer
549 views
best way to create serializable data model
somewhat inexperienced in python. I am coming from C# world, and I am trying to figure out what is the best practice to create a data structure in python that: can have empty fields (None) can have ...
0 votes
2 answers
99 views
Python: Magic method for when the object's reference count changes?
I want to a method that runs when object reference count is changed. is there a method like the following code ? class Foo(): def __method__(self): print("ojbect reference count is ...
0 votes
0 answers
80 views
Should I use Model objects from library or make it myself?
I'm working with gitlab webhooks and I need to choose which data model to use in my project. I'm using the Python-gitlab library to work with gitlab, and this library has its own data models for all ...
0 votes
3 answers
96 views
How to represent the numbers 0 to 3, taking up 2 bits of memory in python
I'm writing code for a Deep Q Network in python. My computer has 32GB of memory but I run into significant issues as the training goes on because the replay buffer maxes out the RAM. I'm looking ...
0 votes
1 answer
443 views
Are there any unique features provided only by metaclasses in Python?
I have read answers for this question: What are metaclasses in Python? and this question: In Python, when should I use a meta class? and skimmed through documentation: Data model. It is very possible ...
2 votes
1 answer
503 views
How can I access the weakref object of the class itself through the class?
As far as I know, __weakref__ is a descriptor defined in class, so that if it invoked from the instances of the class, it will give the weakref object: from weakref import ref class A: pass obj =...
0 votes
1 answer
537 views
Usage of __setattr__ to rewrite whole method of library class issue: missing 1 required positional argument: 'self'
I've got some imported packages with tricky structure and need to call some method that bases on lots of other methods with non-default parameters, which are not class attributes themself like ...