Skip to content

Add support for clr.ImportExtensions #55

Open

Description

@filmor
No description provided.

Activity

  1. den-run-ai commented on Dec 30, 2014

    @den-run-ai
    Contributor
  2. filmor commented on Jan 6, 2015

    @filmor
    MemberAuthor

    It would be even better to have an import hook that installs the extension-functions automatically. I guess the over-loading is the biggest problem here (i.e. we already have a function ToString() implemented for a class and have an extension providing ToString(string format)).

  3. filmor commented on Jun 29, 2015

    @filmor
    MemberAuthor

    According to this http://stackoverflow.com/questions/299515/reflection-to-identify-extension-methods it's quite easy to at least find the correct MethodInfo objects. From skimming the Python.NET code I'd guess that we'd have to rebuild the method objects whenever extensions are imported.

    Is there any particular reason why this is done up-front instead of having a dynamic (cached?) __getattribute__ function that does this on-demand? That would enable us to just invalidate the cache when extensions are imported.

  4. tonyroberts commented on Jun 29, 2015

    @tonyroberts
    Contributor

    One nice side-effect of having the methods built up-front is that you get tab completion in ipython.

  5. filmor commented on Jun 29, 2015

    @filmor
    MemberAuthor

    That we get also by overloading __dir__ which I intend to do anyhow to
    implement DLR stuff.

  6. tonyroberts commented on Jun 29, 2015

    @tonyroberts
    Contributor

    oh ok, yeah in that case I can't immediately think of any reason not to do it dynamically.

  7. bastelflp commented on Jun 23, 2016

    @bastelflp

    Is there any update on this issue?

  8. lcorrigan commented on Jul 10, 2016

    @lcorrigan

    I'm also quite curious of the status of this.

  9. den-run-ai commented on Jul 15, 2016

    @den-run-ai
    Contributor

    Can't you just use the extension method as static method?

    It looks the extension mechanisms was not added to DLR, but somehow
    ironpython has it.

    On Saturday, July 9, 2016, lcorrigan [email protected] wrote:

    I'm also quite curious of the status of this.

    —
    You are receiving this because you commented.
    Reply to this email directly, view it on GitHub
    #55 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe/AHgZ5QWO4E33P0wn0xP_K2QxV3LzEf2Hks5qUE1LgaJpZM4DASTr
    .

  10. filmor commented on Jul 15, 2016

    @filmor
    MemberAuthor

    Yes, using those as static methods works, but can be quite annoying.

    In my opinion, fixing this involves changing how the method resolution works, in that it should be deferred to call-time. Currently, the method objects are built up-front and there is no way to trigger a "refresh".

  11. lcorrigan commented on Jul 18, 2016

    @lcorrigan

    Unfeasible in some cases. When using a .NET library that defines objects which make use of extension methods, you don't know which ones make use of the extension methods. That would be a very hard thing to document in an API as a library author. As a consumer, you get a dll and a help file - not a list of which classes in the API make use of extension methods. You most often don't even know which objects to apply this model to until you see it fail - if you understand the exception thrown.
    A group of us have been using IronPython 2.7 for 3 years now. As a previous user of python .NET years before, I'd really like to move onto CPython 3,5 with python .net now that it's active again but this limitation would be a bit crippling as we make use of extension methods a lot.

  12. filmor commented on Jul 18, 2016

    @filmor
    MemberAuthor

    I'm not quite sure I understand what you are getting at. This feature is only about supporting the shortcut

    ExtensionClass.Func(obj)
    
    =>
    
    obj.Func()
    

    within Python. This resolution is done by the C# compiler up-front AFAIK, that is why the extension method shortcut is not supported on dynamic objects.

    My proposal of how to achieve this is that the __getattr__ method of a random .NET object should be modeled after the normal C# resolution order, i.e. first check if there is a public method on the object itself and then check for fitting extension methods. This is quite a bit different from how it's implemented currently.

  13. lcorrigan commented on Jul 18, 2016

    @lcorrigan

    I'm sorry I was not clear. I'm only hoping to be able to call the method as a member of the class (the way you showed it with obj.Func() ) as well as be able to see 'Func' show up for tab completion / intellisense for 'obj.' which you also touched on earlier. Nothing different from what you were describing - I was only commenting on why it is difficult to go without these two items.

  14. vmuriart commented on Feb 24, 2017

    @vmuriart
    Contributor
  15. den-run-ai commented on Feb 24, 2017

    @den-run-ai
    Contributor

    @vmuriart TDD :)

  16. slide commented on Jan 21, 2022

    @slide
    Contributor
  17. matthiasburger commented on Feb 14, 2023

    @matthiasburger

    is there any update on this? using EFCore with Python.NET doesn't work pretty good without Linq-Extensionsmethods... :)

  18. added a commit that references this issue on Mar 17, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions