Questions tagged [class-attributes]

170 questions
8
votes
3 answers

Deprecating fields in django model

I'm normalizing a database associated with a Django project and will be moving fields to different tables. As part of the implementation process, I'd like to throw a deprecation warning to my colleagues if they attempt to use the old attributes…
8
votes
2 answers

Remove class attribute in inherited class Python

Consider such code: class A (): name = 7 description = 8 color = 9 class B(A): pass Class B now has (inherits) all attributes of class A. For some reason I want B not to inherit attribute 'color'. Is there a possibility to do…
Graf
  • 1,437
  • 3
  • 17
  • 27
8
votes
3 answers

How to pass a dynamic variable into the authorize attribute class in asp.net mvc?

How to pass a dynamic variable into the authorize attribute class in asp.net mvc? For Example I have this piece of code, how can I pass a variable like userRoles variable into the Authorize attribute class? private string userRoles; private string…
Mo Haidar
  • 3,748
  • 6
  • 37
  • 76
8
votes
2 answers

python - Class attributes apparently not inherited

In a recent project I try to do something like this (more complex, but the same result): class MetaA(type): def __new__(cls, name, args, kwargs): print kwargs["foo"] return type.__new__(cls, name, args, kwargs) class A(object): …
thrstein
  • 83
  • 1
  • 5
8
votes
2 answers

How to teach SpecFlow to add additional NUnit attributes to my test class

SpecFlow is great - and it helps us very much to do proper integration testing. One thing I was wondering is whether there's a way to tell SpecFlow to add additional NUnit attributes to the test class it creates in the feature code-behind…
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
8
votes
7 answers

Real world use of custom .NET attributes

What kind of things have you used custom .NET attributes for in the real world? I've read several articles about them, but I have never used custom attributes. I feel like I might be overlooking them when they could be useful. I am talking about…
TWA
  • 12,756
  • 13
  • 56
  • 92
6
votes
5 answers

How to check multiple elements has same class using jquery?

Is it possible to minify this selector? if ($("#element1").hasClass("highlight") && $("#element2").hasClass("highlight") && $("#element3").hasClass("highlight") && $("#element4").hasClass("highlight") && $("#element5").hasClass("highlight")) { …
6
votes
3 answers

What's the simplest most elegant way to utilize a custom attribute

So a little confession, I've never written an attribute class. I understand they serve the purpose of decorating classes with flags or extra functionality possibly. Can someone give me a quick example of not just creating and applying an attribute…
Jimmy Hoffa
  • 5,909
  • 30
  • 53
6
votes
2 answers

When are python classes and class attributes garbage collected?

class Member(object): def __init__(self, identifier): self.identifier = identifier print "Member __init__", self.identifier def __del__(self): print "Member __del__", self.identifier with open("/home/might/"…
5
votes
2 answers

Python paradigm for "derived fields"/"class attributes from calculations"

I have a class that, let's say, computes a person's insurance risk, and a few other variables are computed during computation. I will need access to the risk and the other variables later. class InsuranceRiskModel: self.risk = None …
atp
  • 30,132
  • 47
  • 125
  • 187
5
votes
2 answers

Why can't class attributes be named as reserved words in python?

It seems reserved words can not be used as attributes in python: $ python Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:51:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for…
Daniel Gonzalez
  • 135
  • 2
  • 9
5
votes
2 answers

Python: How to mock class attribute initializer function

I would like to mock a module-level function used to initialize a class-level (not instance) attribute. Here's a simplified example: # a.py def fn(): return 'asdf' class C: cls_var = fn() Here's a unittest attempting to mock…
5
votes
1 answer

Update Ruby class attributes hash when a property changes

I'm trying to write a Ruby class that works similarly to Rails AactiveRecord model in the way that attributes are handled: class Person attr_accessor :name, :age # init with Person.new(:name => 'John', :age => 30) def…
sa125
  • 28,121
  • 38
  • 111
  • 153
4
votes
2 answers

How do you remove a class that matches a pattern from the class attribute, but retain the other classes?

I want to delete the classes that end with 'blue' from the class attribute on all tags sample html

this is blue text

this is red text

This will give…
qodeninja
  • 10,946
  • 30
  • 98
  • 152
4
votes
1 answer

Class attributes dependent on other class attributes

I want to create a class attribute, that are dependent to another class attribute (and I tell class attribute, not instance attribute). When this class attribute is a string, as in this topic, the proposed solution class A: foo = "foo" bar =…
lg53
  • 121
  • 7
1
2
3
11 12