Skip to content

Allow sys.stdout to be replaced #88

Open

Description

@alanjds

google#302 opened on Apr 28, 2017 by @alanjds

Please refer to the discussion on google#290

Do not merge until __getattr__ and __setattr__ is working.

Activity

  1. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by corona10
    Friday Apr 28, 2017 at 15:51 GMT


    I have one thing to discuss here.
    At this point, I think that we should create module directory for these kinds of task. runtime/sysmodule.go => module/sysmodule.go
    WDYT? @trotterdylan @alanjds

  2. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by alanjds
    Friday Apr 28, 2017 at 16:25 GMT


    I totally agree, but am not mature enough on Golang to glance the implications of this change.

  3. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by corona10
    Friday Apr 28, 2017 at 16:27 GMT


    I believe that more modules will be needed. e.g (socketModule etc..)

  4. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by alanjds
    Saturday Apr 29, 2017 at 20:55 GMT


    This is no more a WIP, after changed from __getattr__ to __getattribute__ fixed it.

    Will continue the google#290 implementation over this code.

    Please discuss what changes we want before this (#70) got be merged.

  5. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by trotterdylan
    Saturday Apr 29, 2017 at 23:28 GMT


    I would avoid __getattribute__ and instead use __getattr__. The latter is called only after nothing is found through normal attribute lookup, which is probably what we want in this case.

  6. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by alanjds
    Sunday Apr 30, 2017 at 01:48 GMT


    Me too. But this rabbit hole is getting too deep!
    Let me close some Print() issues first and later I come back to implement __getattr__.

    This __getattr__ issue seems at least one magnitude harder than the other issues anyway. I will need to get "slots" understanding first.

  7. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by alanjds
    Monday May 01, 2017 at 19:00 GMT


    Just to say, tracebacks would be very nice. Took me quite a bit to realize this 'res' typo

  8. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by alanjds
    Saturday Jun 10, 2017 at 15:48 GMT


    I would avoid getattribute and instead use getattr. The latter is called only after nothing is found through normal attribute lookup, which is probably what we want in this case.

    @trotterdylan Are you ok with going on this way, and allow to use getattribute for now, or is better to go develop getattr before keep going on this PR?

  9. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by trotterdylan
    Wednesday Jun 14, 2017 at 14:35 GMT


    I think that __getattr__ should be fairly straightforward to implement. It needs a new slot and fallback logic in grumpy.GetAttr(). Also a few tests that validate the correct attribute resolution.

  10. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by alanjds
    Friday Jun 16, 2017 at 16:40 GMT


    Ok. Then I will chase __getattr__ on another PR.

    Everything else is ok?

  11. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by trotterdylan
    Monday Jun 19, 2017 at 15:05 GMT


    I think this is a little more complicated than I had hoped it would be. What if we get rid of the hybrid module concept and instead swap out sys.__dict__ something like this:

    # lib/sys.py
    from __go__.grumpy import SysDict, SysModules
    SysModules['sys'].__dict__ = SysDict
    ... carry on with the module as normal
    

    Currently __dict__ is not settable, but it will be once google#331 is merged.

  12. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by alanjds
    Monday Jun 19, 2017 at 18:46 GMT


    Hum... the whole point of this PR is allow sys.stdout = StringIO() to propagate to print.

    If SysModules['sys'].__dict__ = SysDict fixes this need and is simpler, lets do it!

    Seems to still need an [SysDict[k] = locals()[k] for k in __all__] at the last line, but for me it looks more ok than the HybridModule stuff.

  13. alanjds commented on Oct 6, 2018

    @alanjds
    Author

    Comment by trotterdylan
    Monday Jun 19, 2017 at 19:58 GMT


    Right, so the trick would be get rid of the Stdout, Stdin and Stderr grumpy package members and instead pull those from SysDict like SysDict.GetItemString(f, "stdin"). I have a change started to see how this would work in practice. I can either finish that up and create a PR, or if you like, you can go that route in this PR.

    Seems to still need an [SysDict[k] = locals()[k] for k in all] at the last line, but for me it looks more ok than the HybridModule stuff.

    I don't think this is necessary if we do the __dict__ assignment at the very top of the module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    imported PRPull Request imported from google/grumpy

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions