Questions tagged [class-attributes]

170 questions
4
votes
3 answers

Python: how to share class attribute between derived classes?

I want to share some information between all the instances of some class and all it's derived classes. class Base(): cv = "some value" # information I want to share def print_cv(self, note): print("{}: {}".format(note, self.cv)) …
lesnik
  • 2,507
  • 2
  • 25
  • 24
4
votes
2 answers

Perl class attribute composition?

Suppose I have multiple roles, each one defining a set of items: package A; use Moose::Role; sub items () { qw/apple orange/ } package B; use Moose::Role; with 'A'; sub items () { qw/watermelon/ } package C; use Moose::Role; sub items () {…
Alessandro
  • 1,336
  • 8
  • 15
4
votes
2 answers

C# Class and Oracle Mapping Parameters

I have a type declared in an Oracle Database: CREATE OR REPLACE TYPE t_project_code_changes AS TABLE OF obj_project_code_change; I map to this type in C# like so [OracleCustomTypeMapping("DEV_SCHEMA.OBJ_PROJECT_CODE_CHANGE")] class…
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
4
votes
2 answers

How does one document class attributes using Doxygen?

I'm attempting to document class attributes using Doxygen. Currently, the protected attributes show up in the list at the top of the page for the specific class. I'd like to put an explanation for them. I've tried using @param [name] [description]…
Logan Bibby
  • 1,167
  • 1
  • 10
  • 31
4
votes
1 answer

Overriding inheritance on intrinsic attributes in C#

After wrestling with a bunch of uncaught exceptions when trying to serialize my classes and subclasses, I've finally understood what my problem had been: [Serializable] isn't inherited by subclasses when applied to a base class. I'm still really…
Mark LeMoine
  • 4,478
  • 3
  • 31
  • 52
4
votes
3 answers

Access base class attribute in derived class - in "class scope"

class Outer(object): class InnerBase(object): _var = {'foo', 'bar'} class Derived(InnerBase): _var = _var | {'baz'} # NameError: name '_var' is not defined _var = InnerBase._var | {'baz'} # name 'InnerBase' is not defined …
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
4
votes
2 answers

'System.Guid' is not an attribute class

I am creating a new dll application with Visual Studio 2013 based on .net 4.5. When trying to define the Guid attribute on my class like this: [Guid("4245366B-0484-4A41-A2E8-C7D9FC3A4ED7")] The compiler gives me the error 'System.Guid' is not an…
codea
  • 1,439
  • 1
  • 17
  • 31
3
votes
4 answers

Class attributes with a "calculated" name

When defining class attributes through "calculated" names, as in: class C(object): for name in (....): exec("%s = ..." % (name,...)) is there a different way of handling the numerous attribute definitions than by using an exec? …
Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
3
votes
1 answer

How can I read the attributes assigned to the properties of a class?

Given the following class Public Class Customer Inherits XPBaseObject Private _CustomerID As Integer = -1 Public Property CustomerID()…
OrElse
  • 9,709
  • 39
  • 140
  • 253
3
votes
2 answers

For the purposes of C# code generation in Sparx Enterprise Architect, is it possible to add class attributes, such as [Serializable]?

I am currently working in Sparx Enterprise Architect (EA) on the design of a system that will be implemented in C# and WPF. I am designing the classes and wondered whether there was any way to give a class .NET attributes such as [Serializable]…
Phil Rogers
  • 545
  • 4
  • 11
3
votes
1 answer

Abstract class attribute in Python?

I have a class like this from abc import ABC class AbstractFoo(ABC): # Subclasses are expected to specify this # Yes, this is a class attribute, not an instance attribute bar: list[str] = NotImplemented # for example class…
3
votes
2 answers

How to reference the type of a private class from an assembly-level attribute?

I have defined an assembly level attribute class FooAttribute like this: namespace Bar { [System.AttributeUsage (System.AttributeTargets.Assembly, AllowMultiple=true)] public sealed class FooAttribute : System.Attribute { public…
Pierre Arnaud
  • 10,212
  • 11
  • 77
  • 108
3
votes
1 answer

using nonlocal or global inside a class body

In python it is valid to use an import statement inside a class to define class variables that are just stolen from other modules: class CustomMath: from math import pi assert isinstance(CustomMath.pi, float) # passes It is also valid to refer…
Tadhg McDonald-Jensen
  • 20,699
  • 5
  • 35
  • 59
3
votes
1 answer

Python: how to make abstract class attribute, with all caps naming convention and linter warnings

I have an abstract base class, with a constant class attribute. How can I force a child class to override it? I would like to keep the all caps PEP8 convention for constants. Sample Code from abc import ABC class BaseClass(ABC): """Some…
3
votes
1 answer

Python, pycharm changes attribute from list to None, why?

When I'm creating a new class, if one of my attribute is an empty list, pychram suggest to change it to this: class meet_angle_cond: def __init__(self, xy_lat_lon_list=None): if xy_lat_lon_list is None: xy_lat_lon_list = [] …
user12177026
1 2
3
11 12