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 (...
classonlymethod decorator/descriptor defined below is like the built-in classmethod, but you're not allowed to call the method on instances, only on the class itself.from typing import Concatenate, ...
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 ...
I wrote a simple code where I override the __getattribute__ method so that it always returns an empty string. But Pyright doesn't understand this and complains "int" is not assignable to &...
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 ...
Passing a class, or a totally different object, as the first argument to method is easy:class Foo: def method(self): ...Foo.method(object()) # pass anything to selfI wonder, is this possible ...
Given an object, how can I make a check if it is a method_descriptor?is_method_descriptor = isinstance(obj, method_descriptor) # does not workThe problem: method_descriptor is a builtin but not an ...
I want to refactor a big part of my code into a generic descriptor for read only attribute access. The following is an example of property based implementationclass A: def __init__(self, n): ...
EDIT This code contains several bugs, see jsbueno's answer below for a correct versionI would like to create read-only attributes that dynamically retrieve values from an internal dictionary. I have ...
I'm trying to use type hints in my code but I simply don't understand how the concept applies to a Python descriptor. The only relevant info I could find on the matter was this 6+ year old post but I ...
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 ...
I want to create a @property like feature with serialization capabilities. It would take some arguments.I have created a descriptor like so:class CustomMethod: def __init__(self, serialize: bool ...
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): &...
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 ...