Re: Block return values (myhdl.BlockError)

Henry Gomersall <[email protected]> Tue, 10 May 2016 11:02:21 +0100
Newsgroups gmane.comp.python.myhdl
Message-ID <[email protected]>
On 10/05/16 10:45, Henry Gomersall wrote:
> On 10/05/16 10:32, Jan Decaluwe wrote:
>> > I have considered this issue for some time now
>> > and I have basically decided to leave the constraints
>> > as they are, that is, blocks should only return
>> > block and instantiator objects.
> I think your reasoning is sound.
> 
> Do you object to alternative strategies for constructing Block
> operators? This could leave @block as the default usual case, with more
> esoteric cases handled by direct access to the construction of the Block
> object. This could allow the best of both worlds - simple default and
> arbitrary control if desired.

Actually, a neat solution could be to allow optional decorator arguments
taking the class constructor and allow subclassing of _Block.

e.g.

class MyBlock(_Block):

    @property
    def some_exposed_property(self):
        return 20

@block(block_class=MyBlock)
def foo():
    ...

In the case of handling alternative default args, it's simply a case
then of an alternative Block. Something like (untested so may be wrong)...

(it actually doesn't matter whether it is right or easy, it provides an
opportunity to add later).

class ExtractExtraArgsBlock(_Block):
    @property
    def extra_args(self):
        return extra_args

    def __init__(self, func, deco, srcfile, srcline, *args, **kwargs):
        self.extra_args = []
        def wrapper_func(*args, **kwargs):
            inst, output_stuff = func(*args, **kwargs)
            self.extra_args.append(output_stuff)
            return inst

        wrapper_srcfile = inspect.getsourcefile(wrapper_func)
        wrapper_srcline = inspect.getsourcelines(wrapper_func)[0]

        super(self, _Block).__init__(
            wrapper_func, deco, wrapper_srcfile,
            wrapper_srcline, *args, **kwargs)

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j