GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cannot get correct overload of generic method · Issue #821 · pythonnet/pythonnet

Cannot get correct overload of generic method #821

New issue
Copy link
New issue
Copy link
Open
Open
Cannot get correct overload of generic method#821
Copy link

Description

@Tobimaru
Tobimaru
opened on Mar 2, 2019
Issue body actions

Environment

  • Pythonnet version: zip archive of master branch
  • Python version: 3.6
  • Operating System: Ubuntu 18.04

Details

  • Describe what you were trying to get done.

Invoke a generic method with multiple overloads.

  • What commands did you run to trigger this issue?

On the C# side I have the following generic method with overloads:

Variable<T> Variable.Constant<T>(T)
VariableArray<T> Variable.Constant<T>(T[])    

On the python side, I'm trying to invoke the second overload by doing:

a = Variable.Constant(System.Array[System.Double]([1.0, 2.0, 3.0]))

But when I check the type of a, it gives Variable[System.Double[]] and not VariableArray[System.Double]. This makes sense since it's ambiguous without specifying the type of the output variable or specifying the type for the function. Since in python I can't pin the output variable to a specific type, I tried to resolve the ambiguity with:

a = Variable.Constant[System.Double](System.Array[System.Double]([1.0, 2.0, 3.0]))

but then I get the exception:

TypeError: No method matches given arguments for Constant

I also tried:

a = Variable.Constant.Overloads[System.Double](System.Array[System.Double]([1.0, 2.0, 3.0]))

but then I get the exception:

TypeError: No match found for signature

It seems that there is pull-request (#227) ongoing, but it looks to have been work in progress for quite a while now. Is this is not priority, is there a workaround that I can try?

Activity

  1. filmor commented on Mar 6, 2019

    @filmor
    filmor
    on Mar 6, 2019
    Member
    More actions

    The method overload resolution of Python.NET is very tricky to get right, as we're dealing with two different type systems that should somehow be made compatible. I'm not sure how #227 would solve this.

  2. Tobimaru commented on Mar 7, 2019

    @Tobimaru
    Tobimaru
    on Mar 7, 2019
    Author
    More actions

    Is there any way to work around this problem? The only thing I can think of is to write a small C# library that explicitly instantiates the generic methods with the types that I need. I hope that python.NET can then resolve the overloads.

  3. filmor commented on Mar 8, 2019

    @filmor
    filmor
    on Mar 8, 2019
    Member
    More actions

    Yes, that approach works fine, and I'm currently not aware of a workaround that doesn't require an additional library.

  4. den-run-ai commented on Mar 8, 2019

    @den-run-ai
    den-run-ai
    on Mar 8, 2019
    Contributor
    More actions

    You can always use reflection, search this issue tracker or stackoverflow "python.net" tag.

  5. Tobimaru commented on Mar 20, 2019

    @Tobimaru
    Tobimaru
    on Mar 20, 2019
    Author
    More actions

    Sorry for the late response. Thanks for the info. I tried with a wrapper library around the generic methods and that seems to work. But now I'm having issues with [] overloads. I haven't tried with using reflections yet, I'll give it a try.

  6. Tobimaru commented on Mar 23, 2019

    @Tobimaru
    Tobimaru
    on Mar 23, 2019
    Author
    More actions

    Reflection doesn't seem to work either. The problem is that in the module that I'm trying to use (infer.net), Variable is an abstract class and Constant is a static method of this abstract class. I don't know how to invoke the method of an abstract class. If I do:

    var_type = dll.GetType("Variable")
    method = var_type.GetMethod("Constant")

    Then I get the error:

    AttributeError: 'NoneType' object has no attribute 'GetMethod'
  7. christabella commented on Jan 13, 2021

    @christabella
    christabella
    on Jan 13, 2021
    Contributor
    More actions

    This is probably too late but an infer.net-specific workaround could be to use Invoker.InvokeStatic(Variable, "Constant", args) e.g.
    https://github.com/dotnet/infer/blob/0c75b5ef4190c5eee55e663741e645cb997b7236/test/TestPython/test_tutorials.py#L217

    Reacted by Hon Fai Choi
  8. greateggsgreg
    added 2 commits that reference this issue on May 10, 2026

    Tests driven by real-world consumer patterns and historical issues

    7f2934b

    test_thread: cover real-world consumer patterns

    275a9f2
  9. filmor
    added 2 commits that reference this issue on May 12, 2026

    test_thread: cover real-world consumer patterns

    d8326cf

    test_thread: cover real-world consumer patterns

    74d12f1
  10. filmor
    added a commit that references this issue on Aug 18, 2026

    test_thread: cover real-world consumer patterns

    3d56611
  11. filmor
    added a commit that references this issue on Sep 14, 2026

    Python 3.14 free-threaded support (#2721)

    7b08d70
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

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.