845 questions
0
votes
3
answers
109
views
If I subclass int, how to make arithmetic methods return the derived type?
I want to construct objects which support arithmetic operations and have extra methods, e.g:
class Timestamp(int):
def as_seconds(self):
return self / 90000
The extra method works:
>&...
0
votes
1
answer
68
views
In subclassing an edit box using SetWindowLongPtrA() to pass a function address, I get an "incompatable type" error
I'm trying to subclass an edit box in a dialog in VS C++ 2022. I want to intercept any key presses in a particular edit box to do further processing.
Here's my code. The 4th line confuses me because I ...
1
vote
2
answers
128
views
How to prevent Javascript super constructor calling a method overridden by a derived class?
I'm new to JS and implementing a polymorphic class hierachy. It appears that within the super constructor (when called from a derived constructor), 'this' refers to the derived class, not the super ...
0
votes
1
answer
111
views
How can I subclass a TButton to owner-draw it?
I want to color a TButton control in C++Builder. I am trying to follow the information I found that suggests using SetWindowLong() to enable the BS_OWNERDRAW style for my TButton control, then catch ...
0
votes
0
answers
121
views
SetWindowSubclass on Windows 10 Notepad
I've been trying to solve this little problem the whole day, and I can't figure out what's wrong. I suppose this is a simple problem for some. So I'm trying to Subclass Notepad with a procedure that ...
1
vote
1
answer
74
views
subclass tuple in Python to simulate infinite repeating sequence?
I have a sequence of 16 elements (dealer and vulnerability of bridge boards, to be specific) that repeat endlessly in theory (in practice it almost never gets past 128, and rarely past 36).
That is, ...
0
votes
0
answers
64
views
What is the best way to access immutable part when subclassing immutable type?
Suppose that you want to create a new subclass for float, using the following code:
class MyFloat(float):
def __new__(cls,number,extra):
return super().__new__(cls,number)
def ...
1
vote
1
answer
220
views
Subclass of pathlib.Path doesn't support "/" operator
I'm attempting to create a subclass of pathlib.Path that will do some manipulation to the passed string path value before passing it along to the base class.
class MyPath(Path):
def __init__(self, ...
1
vote
1
answer
279
views
Tensorflow 2.17 - Saving custom model does not work for me
(tensorflow 2.17, Windows 10)
I can't save and restore a custom model using subclassing method.
Please find below the code to reproduce the problem :
import numpy as np
import tensorflow as tf
x = np....
1
vote
1
answer
128
views
How does JavaScript "decide" how to print a class name?
I'm trying to write an inheritence logic where I clone an input class and inherit from remaining parent classes. In order to do that, I need to create a new class, deep copying one of the classes ...
0
votes
0
answers
93
views
Is it possible to define a subclass in python that creates a new atomic attribute?
I'll call an "atomic" attribute of a python class to be one from which all other user defined attributes derive. For example, the attribute a in the class below is atomic to A because all ...
1
vote
0
answers
182
views
Adding a method to an existing enum in Python
I have an existing enumeration with a number of values defined in package b, and I want to add behavior in the current package a. I understand that you can't directly subclass an enum with existing ...
1
vote
0
answers
93
views
CMFCButton with transparent background
I have developed a class that subclasses from CMFCButton. I load three PNG images (with transparent zones) to the button foreground in the DrawButton function for three states:
Normal
Hovered
Pushed
...
1
vote
0
answers
40
views
Subclassing Pandas Series without losing original methods
I'm trying to implement my subclass of pd.Series, but original pd.Series methods don't work as expected and return Nan
class Subclass(pd.Series):
# see https://pandas.pydata.org/pandas-docs/stable/...
1
vote
2
answers
91
views
Is there a simple way to subclass python's set without redefining all operators?
Is there a way to subclass set, with the binary operator returning the subclassed type, without redefining them ?
example :
class A(set):
pass
a = A([1,2,3]) & A([1,2,4])
a.__class__ == A # ...