Skip to main content
1 vote
1 answer
149 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
2 votes
3 answers
180 views

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, ...
yuri kilochek'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
0 answers
70 views

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 &...
Alex Filiov's user avatar
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
2 votes
1 answer
69 views

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 self I wonder, is this possible ...
Daraan's user avatar
  • 5,166
1 vote
1 answer
82 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,166
1 vote
1 answer
85 views

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 implementation class A: def __init__(self, n): ...
Yehui He's user avatar
1 vote
1 answer
78 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
1 vote
0 answers
166 views

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 ...
YoRHa_A2's user avatar
2 votes
3 answers
197 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
16 views

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 ...
FTG's user avatar
  • 75
0 votes
0 answers
46 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
0 votes
2 answers
90 views

Here is descriptor class: #descriptor class Validator: def __set_name__(self,owner,name): self.private_name = '_' + name def __set__(self,obj,value): self.validate(value) ...
Subham Kumar'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

15 30 50 per page
1
2 3 4 5
14