Re: [pygccxml-development] Two patches proposal
Brought to you by:
mbaas,
roman_yakovenko
From: Berserker <ber...@ho...> - 2009-12-23 14:04:57
|
> The short answer is no :-(. The main reason for it: such code does not > meat user expectations. Let me explain: > > foo = Foo() > foo.Bar.x = 2 > assert foo.Bar.x == 2 > > The following is explanation how I thought "add_properties" > functionality should be used in such case. > > class custom_name_based_recognizer_t( name_based_recognizer_t ): > def __init__( ... ): ... > > def check_type_compatibility(self, fget, fset): > <your code > > > cls = mb.class_( ... ) > cls.add_properties( recognizer=custom_name_based_recognizer_t() ) > > Could it be an acceptable solution? Yes, I'm actually using that solution. I'm sad about "user expectations" but what about this case then (without the patch): foo = Foo() b1 = foo.Bar b1.x = 2 b2 = foo.Bar b2.x = ? I think that this is another case where we can discuss about "user expectations", what about? > I am not sure. According to the MSDN ( > http://msdn2.microsoft.com/en-us/library/h1y7x448.aspx ) "...C++ > constructors that have just one parameter automatically perform > implicit type conversion. ...". In your case the constructor has 2 > arguments. I tested the following code with gcc 4.4.1 > > struct Foo{ > Foo( int i, bool b=false ){} > }; > > void dosmth( Foo ){ > } > > int main( int argc, const char* argv[] ){ > dosmth( 11 ); > }; > > and it compiles fine. > > I don't know C++ at the level of standard. Do you know what the > standard says? Does the code compile fines with MSVC compiler? > > > How can I write it? > > It is not a problem to write it: > > if 1 != len( self.required_args ): > return False > > > Any hope to apply the code to the svn? > > The first issue - I believe you have a solution, the second one - I > prefer to know the answers. If they are positive - I will apply the > patch almost immediately. I'm not a "standard expert" too, but I can confirm that your code does compile on MSVC (tested on VC2005 and VC2008). Actually I "tweaked" the method in this way (probably it could be written better...): def override_does_define_implicit_conversion(self): if self.parent.is_abstract: return False if self.is_copy_constructor: return False args = len(self.arguments) if args != 1: if args > 1: for arg in self.arguments[1::]: if not arg.default_value: return False else: return False if self.parent.find_out_member_access_type(self) != declarations.ACCESS_TYPES.PUBLIC: return False return True decl_wrappers.calldef_wrapper.constructor_t.does_define_implicit_conversion = override_does_define_implicit_conversion It works but as you probably know I don't like this solution :) Thanks for your help as usual ;) _________________________________________________________________ Giochi, radio, TV... E tutti i tuoi amici. Cercali su Messenger http://www.messenger.it/home_comunica.aspx |