[Python.NET] Stricter types in 3.0
Felix Bourbonnais <felix.bourbonnais-I5kDqsOpojRSLAGY5zujZ1aTQe2KTcn/@public.gmane.org> Thu, 3 Feb 2022 14:33:20 -0500
| Newsgroups | gmane.comp.python.dotnet |
|---|---|
| Message-ID | <CAHfO0Ls1UW-uWja-rgy7-o_O0tDy3CHHdM7rjaCeZq9z8FaFbA@mail.gmail.com> |
--===============3603964420991950184==
Content-Type: multipart/alternative; boundary="0000000000009e2cbc05d72235b1"
--0000000000009e2cbc05d72235b1
Content-Type: text/plain; charset="UTF-8"
Hello, as was discussed in the bi-weekly meeting, the newest version seems
to introduce stricter type checking. Here's a snippet that exhibits two
issues.
using (Py.GIL())
{
dynamic sysmod = Py.Import("sys");
dynamic syspath = sysmod.path;
bool found = false;
foreach (var path in syspath)
{
if (path == Path.GetFullPath("some/test/path/").Replace("\\", "/"))
{
found = true;
break;
}
}
}
The first is a runtime exception with syspath:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : Cannot implicitly
convert type 'Python.Runtime.PyObject' to 'System.Collections.IEnumerable'.
An explicit conversion exists (are you missing a cast?)
The second is maybe a non-issue, but I think it used to work. If syspath is
made to be of type PyList there is now a compiler error: error CS0019:
Operator '==' cannot be applied to operands of type 'PyObject' and 'string'
Thanks
--0000000000009e2cbc05d72235b1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Hello, as was discussed in the bi-weekly meeting, the=
newest version seems to introduce stricter type checking. Here's a sni=
ppet that exhibits two issues.<br></div><div><br></div><div>using (Py.GIL()=
)<br>{<br>=C2=A0 =C2=A0 dynamic sysmod =3D Py.Import("sys");<br>=
=C2=A0 =C2=A0 dynamic syspath =3D sysmod.path;<br>=C2=A0 =C2=A0 bool found =
=3D false;<br>=C2=A0 =C2=A0 foreach (var path in syspath)<br>=C2=A0 =C2=A0 =
{<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (path =3D=3D Path.GetFullPath("som=
e/test/path/").Replace("\\", "/"))<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 found =3D =
true;<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;<br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 }<br>=C2=A0 =C2=A0 }<br>}</div><div><br></div><div>The first =
is a runtime exception with syspath: Microsoft.CSharp.RuntimeBinder.Runtime=
BinderException : Cannot implicitly convert type 'Python.Runtime.PyObje=
ct' to 'System.Collections.IEnumerable'. An explicit conversion=
exists (are you missing a cast?)</div><div>The second is maybe a non-issue=
, but I think it used to work. If syspath is made to be of type PyList ther=
e is now a compiler error: error CS0019: Operator '=3D=3D' cannot b=
e applied to operands of type 'PyObject' and 'string'</div>=
<div><br></div><div><br></div><div>Thanks</div></div>
--0000000000009e2cbc05d72235b1--
--===============3603964420991950184==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
PythonNet mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/pythonnet.python.org/
Member address: [email protected]
--===============3603964420991950184==--