Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
142 views

I'm developing a Python interpreter from scratch in C++ as a hobby project to deepen my understanding of the language's internals. I'm currently stuck on implementing the attribute lookup mechanism (...
Antonio Sidnei's user avatar
1 vote
1 answer
76 views

For a project, I want to prevent the use of certain methods in an overriding class. As this happens rather frequently, I am using a metaclass to block many methods at once (how and why is not within ...
502E532E's user avatar
  • 581
1 vote
1 answer
128 views

I want to explain to Pyright that my variables in class and instance have different types. I managed to overload __get__ method to achieve this, but now Pyright complains about initialization of ...
Alex Filiov's user avatar
1 vote
1 answer
81 views

Given an object, how can I make a check if it is a method_descriptor? is_method_descriptor = isinstance(obj, method_descriptor) # does not work The problem: method_descriptor is a builtin but not an ...
Daraan's user avatar
  • 5,136
1 vote
1 answer
74 views

EDIT This code contains several bugs, see jsbueno's answer below for a correct version I would like to create read-only attributes that dynamically retrieve values from an internal dictionary. I have ...
peich's user avatar
  • 33
2 votes
3 answers
196 views

I can't seem to find a definitive answer on the matter and I guess the reason is because it depends on the situation. a, b and c (and d, e, f... as only 3 attributes are listed in this example for ...
YoRHa_A2's user avatar
0 votes
0 answers
43 views

I'm building my own ORM in Python and ran into an issue. I want to track the access to class variables in order to know which ForeignKey is being used in each part of my code. class IQuery(ABC): &...
phzamora's user avatar
1 vote
1 answer
56 views

I would like to be able to decorate instance methods with a class Step such that the methods are replaced by a Step object. At the same time, I'd like to have the option be able to instantiate a step ...
mauro's user avatar
  • 11
2 votes
0 answers
231 views

I have a couple of data structure classes that are intended to have public read-only attributes. I cannot use dataclasses or namedtuples as I need the ability to define args, kwargs in the child ...
Parikshit's user avatar
-1 votes
1 answer
79 views

I have been refactoring a text class meant for blitting text to the screen. I recently learned about the @property decorator and thought using it in this class would help. Here is a stripped down ...
r5ne's user avatar
  • 13
3 votes
3 answers
118 views

Not sure if this is feasible or not. The implementation/example below is dummy, FYI. I have a Python class, Person. Each person has a public first name and a public last name attribute with ...
pemm's user avatar
  • 302
1 vote
1 answer
61 views

I need to get the name of a variable from within a function it call during assignment. For example if we take the code: class CharField: def __init__(self): self.field_name = ??? ...
Carl L's user avatar
  • 53
0 votes
1 answer
103 views

Recently, with the change of the @classmethod decorator no longer being able to wrap the @property decorator (Python >= 3.11), there has been significant interest in how to create a @classproperty ...
Mr G's user avatar
  • 268
0 votes
0 answers
55 views

This is my code: class Property: def __init__(self, fget, fset): self.fget = fget self.fset = fset def __get__(self, obj, objtype=None): return self.fget(obj) ...
forstack overflowizi's user avatar
-1 votes
1 answer
88 views

I have a class with an attribute ax_mask. The attribute is list like. When I change the whole attribute or just an element of it, I need some other attribute (window) in the class to be updated (i.e. ...
fuhrmanj's user avatar
0 votes
0 answers
43 views

I have a number of XML message types with an elaborate header and sequence structure, but separate business message types. I'm trying convert these to objects in Python, and so far my bottom-level ...
Woody1193's user avatar
  • 8,202
4 votes
1 answer
113 views

EDIT: I extended the example to show the more complex case that I was talking about before. Thanks for the feedback in the comments. Some more context: I am mostly interested in this on a theoretical ...
Alexander's user avatar
  • 394
3 votes
2 answers
709 views

from typing import NamedTuple from functools import cached_property class Rectangle(NamedTuple): x: int y: int @cached_property def area(self): return self.x * self.y I ...
COVFEFE-19's user avatar
3 votes
1 answer
129 views

I noticed that contrary to the classmethod and staticmethod decorators, the property decorator overrides the object.__getattribute__ method: >>> list(vars(classmethod)) ['__new__', '__repr__',...
Géry Ogam's user avatar
  • 8,434
2 votes
3 answers
181 views

I have a innerclass decorator/descriptor that is supposed to pass the outer instance to the inner callable as the first argument: from functools import partial class innerclass: def __init__(self, ...
InSync's user avatar
  • 12.2k
1 vote
2 answers
129 views

I want to have a class with dictionaries that contain nodes, but nodes can be of several sorts: points, vertices,... (and possible others) I want to efficiently loop and access over either one of ...
Jaka Belec's user avatar
0 votes
1 answer
113 views

Suppose cls is a class in python. cls.__getattribute__ returns the __getattribute__ function defined on object, but it doesn't bind cls to this function. According to the descriptor protocol, cls is ...
Zhang Daniel's user avatar
5 votes
3 answers
188 views

I need some help with descriptors in python. I wrote an automatic translator from perl to python (Pythonizer) and I'm trying to implement tied scalars, which is basically an object that acts as a ...
snoopyjc's user avatar
  • 633
0 votes
0 answers
49 views

Could you explain why new bound method is created each time when trying to access same method of the same class instance? class MyClass: def my_method(self): print(f"Called bounded to ...
GopherM's user avatar
  • 720
0 votes
2 answers
320 views

Why is this raising an AttributeError? class A: def f(self): print(super().__dict__) A().f() # raises AttributeError: 'super' object has no attribute '__dict__'
zwithouta's user avatar
  • 1,611

1
2 3 4 5