All Questions
Tagged with meta-programming object-oriented
18 questions
1
vote
1
answer
722
views
AutoBind TypeScript decorator
Idea is to have an AutoBind decorator which you could append in front of any method to have it preserve its own this, instead of manually binding it when called.
<...
6
votes
2
answers
478
views
LazyEnum with validation
Motivation
In the standard Python library enum, a subclass of Enum would create all its members upon class creation. This can ...
1
vote
0
answers
84
views
Using metaclass to decorate derived classes to be `attrs` classes
I am currently developing a framework to facilitate writing controller programs for scientific instruments. I use attrs extensively in the internal parts of the ...
7
votes
2
answers
155
views
Python class compressor
After watching this presentation, I decided that it would be a good project for me to undergo to practice my python skills. A summary of the presentation:
Jack ...
3
votes
0
answers
83
views
Metaclass to run a __first__ method for the first instantiation of a class
I had an idea for a __first__ special method for a class. It would be run after __new__ and before ...
12
votes
1
answer
550
views
Using decorated methods in a subclass of deque to dump its state to a JSON file
I am sub-classing an object in python and I need to overload a bunch of the methods with very similar logic, essentially a call to super() and then some additional operations. I want to avoid ...
1
vote
1
answer
125
views
Defining many HTTP request methods in a class using partialmethods
I am using an object that expects a keyword argument for every call, but I never intend to change it. In this case a timeout of 10. What is the best way to add a partialmethods for each attributes.
...
5
votes
0
answers
891
views
Writing a metaclass to ensure a class is thread-safe
Python allows the creation of classes to be modified via metaclasses. They can perform all sorts of operations that might appear to be magical to languages that do not have the capability. The goal of ...
1
vote
0
answers
1k
views
Marking a class as final or sealing a class
Which of these metaclasses should be preferred, and is there room for improvement?
Some people are not familiar with the philosophies that come with working in Python and have a desire embedded in ...
10
votes
2
answers
4k
views
Mutable Named Tuple - or - Slotted Data Structure
A question I answered on Stack Overflow asked for a mutable named tuple.
The naive answer would probably tell them they just want to define a custom object.
However, named tuples take up a lot ...
5
votes
0
answers
715
views
Implement OO interfaces in Python
Edit: Whoops! I just remembered there's already an long-lived package for this, zope.interface. I'd like a review all the same.
This is a proof-of-concept ...
4
votes
0
answers
91
views
Creating companion classes that are `inherited` onto any sub-classes
The idea for the code I have written came about due to the acts_as_versioned gem which automatically nests a Version class onto ...
5
votes
1
answer
740
views
Descriptor class with advanced (inspect/metaclass) functionality
Having answered this question over on Programmers.SE, I found myself wondering how much effort it would be to write a descriptor that can automatically figure out what the 'destination' attribute ...
4
votes
1
answer
820
views
Meta-class to allow inspection of all __slots__of a class
If classes provide __slots__ and at the same time inherit from another class also providing __slots__, there is no ...
11
votes
2
answers
1k
views
Generating and calling code on the fly
Delegate
This class module defines what I'm calling, in this context, a Delegate - here a function that can take a number of parameters, evaluate a result, and ...
9
votes
3
answers
1k
views
Ugly workaround to get the vbext_ProcKind of a procedure is breaking encapsulation
This is a follow up to Extending the VBAExtensibility Library. It turns out that code had a really nasty bug. Anytime vbeProcedure.StartLine got called, I was ...
12
votes
1
answer
5k
views
Extending the VBA Extensibility Library
The Microsoft Visual Basic for Applications Extensibility library let's us meta-program VBA, but the way it handles (or rather, doesn't handle) getting to the actual subs and functions is clunky at ...
2
votes
1
answer
185
views
Duplicating Rails model for a form with meta-programming
Can someone please review my code:
...