Skip to main content
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
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
115 views

Just going the straight way like this, doesn't seem to work in python 3. import ctypes class cA(ctypes.Structure): _fields_ = [("a", ctypes.c_ubyte)] def __init__(self): ...
Roling Tom Role's user avatar
1 vote
1 answer
85 views

Is it possible to access the object instance in a Python @classmethod annotated function when the call occurs via the instance itself rather than the class? class Foo(object): def __init__(self, ...
orange's user avatar
  • 8,252
2 votes
1 answer
810 views

Of the many examples of using @field_validators and @model_validators in Pydantic's documentation, the @classmethod decorator is frequently applied to the method first. Here is one of the examples ...
oweydd's user avatar
  • 141
2 votes
1 answer
80 views

As far as I understand, the difference between @classmethod and @staticmethod is the cls parameter which is used so a class can construct instances of subclasses. I have encountered some issues with ...
mqnc's user avatar
  • 766
0 votes
0 answers
32 views

Say I have a model called Book: class Book(EOModel): title = models.CharField(max_length=100, null=False, blank=False) subtitle = models.CharField(max_length=100, null=True, blank=True) ...
niaei's user avatar
  • 2,629
0 votes
1 answer
30 views

ValidateSet is a great feature in Powershell 5.1. Unfortunately, you cannot use it on parameters in class instance (object) functions. Is there a way to force the use of ValidateSet anyways? Note: ...
The-Stanislav's user avatar
0 votes
1 answer
49 views

I'm reading through the documentation for the schedule API and in the "Run in the Background" example they define the run method as a class method in their ScheduleThread class. The code is ...
hypovisor's user avatar
0 votes
2 answers
47 views

I have the following piece of code - simplified version of what I want to do. But it gives me a recursion error. class File: def __new__(cls, filename): extension = filename.split(".&...
gromajus's user avatar
5 votes
3 answers
135 views

Dummy scenario: # where I want to collect my decorated callbacks cbs = [] # decorator to mark a callback to be collected def my_deco(cb): cbs.append(cb) return cb class C: @my_deco @...
Vito De Tullio's user avatar
0 votes
0 answers
82 views

I would like to write an unit test for an instance method of a class under test containing some simple logic but calling another more complicated instance method. I would like to wrap the complicated ...
Wör Du Schnaffzig's user avatar
0 votes
0 answers
26 views

Is it bad practice to performm a try/except check within a classmethod and return an instance only if everything went well, or should I check everything inside __init__()? Alternatively, is there ...
Raven's user avatar
  • 133
0 votes
2 answers
55 views

I want to compare two integer fields inside a method in a django model. The two fields are not correctly getting compared and it is throwing an error for example: total_slots = models.IntegerField(...
Neo Jabin's user avatar
0 votes
3 answers
86 views

Example.create( attribute1 = "asdf", attribute2 = "asdf2", attribute3 = "and 20 more attributes" ) But how do I conveniently make variable2 = "qwer" if ...
daveasdf_2's user avatar

15 30 50 per page
1
2 3 4 5
62