Skip to main content

All Questions

Filter by
Sorted by
Tagged with
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. <...
Ilija Ivic's user avatar
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 ...
user141240's user avatar
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 ...
Çağlar Kutlu's user avatar
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 ...
Linny's user avatar
  • 10.4k
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 ...
13ros27's user avatar
  • 390
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 ...
Alex's user avatar
  • 223
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. ...
Brian's user avatar
  • 297
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 ...
Noctis Skytower's user avatar
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 ...
Noctis Skytower's user avatar
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 ...
Aaron Hall's user avatar
  • 1,568
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 ...
shadowtalker's user avatar
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 ...
br3nt's user avatar
  • 242
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 ...
jonrsharpe's user avatar
  • 13.9k
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 ...
SmCaterpillar's user avatar
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 ...
Mathieu Guindon's user avatar
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 ...
RubberDuck's user avatar
  • 30.9k
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 ...
RubberDuck's user avatar
  • 30.9k
2 votes
1 answer
185 views

Duplicating Rails model for a form with meta-programming

Can someone please review my code: ...
Arthur Corenzan's user avatar