FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Enumerable First/Last using Python list. · Issue #113 · pythonnet/pythonnet · GitHub

Repository navigation

Enumerable First/Last using Python list. #113

Closed

Description

The following test currently crashes the runtime (stack trace included below).

class EnumerableTest(unittest.TestCase):
    def testFirstAndLast(self):
        values = [1, 2, 3]
        self.assertTrue(Enumerable.First(values) == 1)
        self.assertTrue(Enumerable.Last(values) == 3)
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at Python.Runtime.MethodBinder.MatchParameters(MethodInfo[] mi, Type[] tp)
   at Python.Runtime.MethodBinder.Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo)
   at Python.Runtime.MethodBinder.Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo)
   at Python.Runtime.MethodObject.Invoke(IntPtr target, IntPtr args, IntPtr kw, MethodBase info)
   at Python.Runtime.MethodBinding.tp_call(IntPtr ob, IntPtr args, IntPtr kw)
   at Python.Runtime.Runtime.Py_Main(Int32 argc, String[] argv)
   at Python.Runtime.PythonConsole.Main(String[] args)

Do you expect this to work correctly?

Thanks,

Activity

  1. den-run-ai commented on Jan 22, 2016

    Contributor

    values = [1, 2, 3] is PyList and hence only implements IEnumerable basic interface (not generic):

    https://msdn.microsoft.com/en-us/library/system.collections.ienumerable(v=vs.110).aspx

  2. tonyroberts commented on Jan 22, 2016

    Contributor

    @denfromufa it shouldn't crash the runtime though, it should raise a Python exception if there's a problem.

  3. galpin commented on Jan 22, 2016

    Author
  4. den-run-ai commented on Jan 31, 2016

    Contributor

    full traceback from debug build (after tp_call):

    >   Python.Runtime.dll!Python.Runtime.MethodBinder.MatchParameters(System.Reflection.MethodInfo[] mi, System.Type[] tp) Line 77 C#
        Python.Runtime.dll!Python.Runtime.MethodBinder.Bind(System.IntPtr inst, System.IntPtr args, System.IntPtr kw, System.Reflection.MethodBase info, System.Reflection.MethodInfo[] methodinfo) Line 345    C#
        Python.Runtime.dll!Python.Runtime.MethodBinder.Invoke(System.IntPtr inst, System.IntPtr args, System.IntPtr kw, System.Reflection.MethodBase info, System.Reflection.MethodInfo[] methodinfo) Line 363  C#
        Python.Runtime.dll!Python.Runtime.MethodObject.Invoke(System.IntPtr target, System.IntPtr args, System.IntPtr kw, System.Reflection.MethodBase info) Line 65    C#
        Python.Runtime.dll!Python.Runtime.MethodBinding.tp_call(System.IntPtr ob, System.IntPtr args, System.IntPtr kw) Line 179    C#
    

    autos:

            count   0   int
    -       mi  {System.Reflection.MethodInfo[2]}   System.Reflection.MethodInfo[]
    -       [0] {TSource First[TSource](System.Collections.Generic.IEnumerable`1[TSource])} System.Reflection.MethodInfo {System.Reflection.RuntimeMethodInfo}
            Attributes  Public | Static | HideBySig System.Reflection.MethodAttributes
            CallingConvention   Standard    System.Reflection.CallingConventions
            ContainsGenericParameters   true    bool
    +       CustomAttributes    Count = 2   System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData> {System.Collections.ObjectModel.ReadOnlyCollection<System.Reflection.CustomAttributeData>}
    +       DeclaringType   {Name = "Enumerable" FullName = "System.Linq.Enumerable"}   System.Type {System.RuntimeType}
            IsAbstract  false   bool
            IsAssembly  false   bool
            IsConstructor   false   bool
            IsFamily    false   bool
            IsFamilyAndAssembly false   bool
            IsFamilyOrAssembly  false   bool
            IsFinal false   bool
            IsGenericMethod true    bool
            IsGenericMethodDefinition   true    bool
            IsHideBySig true    bool
            IsPrivate   false   bool
            IsPublic    true    bool
            IsSecurityCritical  false   bool
            IsSecuritySafeCritical  false   bool
            IsSecurityTransparent   true    bool
            IsSpecialName   false   bool
            IsStatic    true    bool
            IsVirtual   false   bool
            MemberType  Method  System.Reflection.MemberTypes
            MetadataToken   100665141   int
    +       MethodHandle    {System.RuntimeMethodHandle}    System.RuntimeMethodHandle
            MethodImplementationFlags   IL  System.Reflection.MethodImplAttributes
    +       Module  {System.Core.dll}   System.Reflection.Module {System.Reflection.RuntimeModule}
            Name    "First" string
    +       ReflectedType   {Name = "Enumerable" FullName = "System.Linq.Enumerable"}   System.Type {System.RuntimeType}
    +       ReturnParameter {TSource }  System.Reflection.ParameterInfo {System.Reflection.RuntimeParameterInfo}
    +       ReturnType  {Name = "TSource" FullName = null}  System.Type {System.RuntimeType}
    +       ReturnTypeCustomAttributes  {TSource }  System.Reflection.ICustomAttributeProvider {System.Reflection.RuntimeParameterInfo}
    +       Non-Public members      
    -       [1] {TSource First[TSource](System.Collections.Generic.IEnumerable`1[TSource], System.Func`2[TSource,System.Boolean])}  System.Reflection.MethodInfo {System.Reflection.RuntimeMethodInfo}
            Attributes  Public | Static | HideBySig System.Reflection.MethodAttributes
            CallingConvention   Standard    System.Reflection.CallingConventions
            ContainsGenericParameters   true    bool
    +       CustomAttributes    Count = 2   System.Collections.Generic.IEnumerable<System.Reflection.CustomAttributeData> {System.Collections.ObjectModel.ReadOnlyCollection<System.Reflection.CustomAttributeData>}
    +       DeclaringType   {Name = "Enumerable" FullName = "System.Linq.Enumerable"}   System.Type {System.RuntimeType}
            IsAbstract  false   bool
            IsAssembly  false   bool
            IsConstructor   false   bool
            IsFamily    false   bool
            IsFamilyAndAssembly false   bool
            IsFamilyOrAssembly  false   bool
            IsFinal false   bool
            IsGenericMethod true    bool
            IsGenericMethodDefinition   true    bool
            IsHideBySig true    bool
            IsPrivate   false   bool
            IsPublic    true    bool
            IsSecurityCritical  false   bool
            IsSecuritySafeCritical  false   bool
            IsSecurityTransparent   true    bool
            IsSpecialName   false   bool
            IsStatic    true    bool
            IsVirtual   false   bool
            MemberType  Method  System.Reflection.MemberTypes
            MetadataToken   100665142   int
    +       MethodHandle    {System.RuntimeMethodHandle}    System.RuntimeMethodHandle
            MethodImplementationFlags   IL  System.Reflection.MethodImplAttributes
    +       Module  {System.Core.dll}   System.Reflection.Module {System.Reflection.RuntimeModule}
            Name    "First" string
    +       ReflectedType   {Name = "Enumerable" FullName = "System.Linq.Enumerable"}   System.Type {System.RuntimeType}
    +       ReturnParameter {TSource }  System.Reflection.ParameterInfo {System.Reflection.RuntimeParameterInfo}
    +       ReturnType  {Name = "TSource" FullName = null}  System.Type {System.RuntimeType}
    +       ReturnTypeCustomAttributes  {TSource }  System.Reflection.ICustomAttributeProvider {System.Reflection.RuntimeParameterInfo}
    +       Non-Public members      
            tp  null    System.Type[]
    
  5. den-run-ai commented on Jan 31, 2016

    Contributor

    using pull request #126 the following proper exception is raised:

    >>> Enumerable.First(values)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: No method matches given arguments
    
  6. tonyroberts commented on Feb 1, 2016

    Contributor

    thanks, that PR has been merged.

    cheers,
    Tony

  7. den-run-ai commented on Feb 9, 2016

    Contributor

    @tonyroberts @galpin I added more similar checks in #129

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


      Back | FazBrowse Home | New Git URL