bugpyFormex - Bugs: bug #43007, Can the default of class...

 
 

bug #43007: Can the default of class mydict.Dict be set to returnNone?

Submitter:  francesco <francio>
Submitted:  Sun 17 Aug 2014 09:46:43 PM UTC
   
 
Category:  Core Severity:  3 - Normal
Item Group:  Feature request Status:  None
Privacy:  Public Assigned to:  bverheg
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 21 Aug 2014 10:28:29 AM UTC, comment #4: 

After the last discussion and clarifications from benedict. I suppose there is no need to introduce this change.
and I cannot see any place where it is needed. closing the bug

francesco <francio>
Group Member
Wed 20 Aug 2014 10:41:07 AM UTC, comment #3: 

I think the possibility to switch CDictto cascade only thru
CDict directories is a good idea.

I will use the 'if k in ' option to check data in fe_abq
so do you think it is a good idea to store all additional keyword parameters in abaqus with key 'options'?

francesco <francio>
Group Member
Wed 20 Aug 2014 10:22:55 AM UTC, comment #2: 

The PropertyDB class was not intended to be Abaqus specific. It uses CDict to allow different ways of specifying properties. E.g.


prop1 = CDict({ 'young_modulus': 207000. })

steel = CDict({ 'young_modulus': 207000. })
prop2 = CDict({ 'mat': steel })

elastic = CDict({ 'young_modulus': 207000. })
mat = CDict({ 'elastic': elastic })
prop3 = CDict({ 'mat': mat })


In all three cases you can just use `if propn.young_modulus:` to get the required value.

If you want to control the dict level where the property resides, you should indeed use `if 'key' in propn:`

Note that CDict was originally designed to cascade only thru
CDict directories. I do not remember why/when it was changed, but we could investigate the possibility to reintroduce the limitation of only cascading into CDicts, possibly as an option.

Change the default of Dict to returnNone is not a good idea, because that could break a lot of other code.


Benedict Verhegghe <bverheg>
Group administrator
Tue 19 Aug 2014 10:32:17 AM UTC, comment #1: 

I am also wondering why properytDB returns the props as CDict.
this is sometimes a bit annoying when looking in the propertyDB because prevents using same keys in Dict or dict which are stored at a deeper level 'prop' . for example i want to create a property which has a key 'options' (a default name for a dictionary via fmtOptions to avoid check for all abaqus keyword options in fe_abq )



P=PropertyDB()
prop=Dict('key':'value')
attribute=Dict('options':'opvalue')
P.Prop(myprop=prop,attribute=attribute)
props=P.getProp(attr='attribute')
for p in props:
   if p.options:
      print(p)
   # this will give the attibute.options and not None


Should not be better to set it as a Dict with returnNone instead of CDict?




francesco <francio>
Group Member
Sun 17 Aug 2014 09:46:43 PM UTC, original submission:  

Referring to the plugin fe_abq there are a lot of keys that should be checked. Now the problem is taht most of the key are checked in this way

if propdict.key:

if the key is not present this will not raise error only if you define a CDict or you set default to returnNone in Dict.
Though CDict will check if the key is present in any Dict which sometimes is not what is needed.the other option is to check if the key is present using

if 'key' in propdict:

can we change the default and keep

if propdict.key:

or when needed I have to use

if 'key' in propdict:


francesco <francio>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bverheg (Posted a comment)
  • -email is unavailable- added by francio (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-08-21 francio Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code