Comments (8)
Yes, that looks like a problem. It looks like the Python bindings only handle overloads based on the number of arguments, but in this case there are two overloads that take one argument. There is a related discussion at #735 (comment) that describes this in more detail. So I think the solution here is to modify the generator to catch cases like this and create a separate method for one of the overloads.
from xlang.
The discussion I linked to actually suggested handling it before that. Instead of trying to inspect the types in a single method call, the method should be split into 2 methods.
from xlang.
I pushed a change to implement the recommended handling using the DefaultOverloadAttribute
.
So in this specific case, the DeviceClass
arg is the default overload for the 1 arg overload. So to use the string argument for the first argument, you need to use the 2 argument overload. The second argument is an iterator, so you can just supply an empty list.
await DeviceInformation.find_all_async(selector, [])
from xlang.
I have a fork of this project where I have fixed lots of bugs, including serious ones like memory leaks and use after free. It also include type hints which would probably help solve your question as well. You can find current latest CI builds at https://github.com/dlech/xlang/actions/runs/1642108211.
from xlang.
Thanks @dlech I tried your build. Now the error is a bit more descriptive:
line 10, in get_all_devices
devices = await DeviceInformation.find_all_async(selector)
TypeError: an integer is required (got type str)
Looking at the cpp file for Windows.Devices.Enumeration the logic looks something like this:
static PyObject* DeviceInformation_FindAllAsync(PyObject* /*unused*/, PyObject* args) noexcept
{
Py_ssize_t arg_count = PyTuple_Size(args);
if (arg_count == 3)
{
try
{
auto param0 = py::convert_to<winrt::hstring>(args, 0);
auto param1 = py::convert_to<winrt::Windows::Foundation::Collections::IIterable<winrt::hstring>>(args, 1);
auto param2 = py::convert_to<winrt::Windows::Devices::Enumeration::DeviceInformationKind>(args, 2);
return py::convert(winrt::Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(param0, param1, param2));
}
catch (...)
{
py::to_PyErr();
return nullptr;
}
}
else if (arg_count == 0)
{
try
{
return py::convert(winrt::Windows::Devices::Enumeration::DeviceInformation::FindAllAsync());
}
catch (...)
{
py::to_PyErr();
return nullptr;
}
}
else if (arg_count == 1)
{
try
{
auto param0 = py::convert_to<winrt::Windows::Devices::Enumeration::DeviceClass>(args, 0);
return py::convert(winrt::Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(param0));
}
catch (...)
{
py::to_PyErr();
return nullptr;
}
}
else if (arg_count == 1)
{
try
{
auto param0 = py::convert_to<winrt::hstring>(args, 0);
return py::convert(winrt::Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(param0));
}
catch (...)
{
py::to_PyErr();
return nullptr;
}
}
else if (arg_count == 2)
{
try
{
auto param0 = py::convert_to<winrt::hstring>(args, 0);
auto param1 = py::convert_to<winrt::Windows::Foundation::Collections::IIterable<winrt::hstring>>(args, 1);
return py::convert(winrt::Windows::Devices::Enumeration::DeviceInformation::FindAllAsync(param0, param1));
}
catch (...)
{
py::to_PyErr();
return nullptr;
}
}
else
{
py::set_invalid_arg_count_error(arg_count);
return nullptr;
}
}
Is it only entering the first else if (arg_count == 1)
block and not the second one?
from xlang.
I am not an expert when it comes to c/cpp but looks like we need to do something in write_method_overloads
function in https://github.com/microsoft/xlang/blob/master/src/tool/python/code_writers.h
from xlang.
I just found this design note: https://devblogs.microsoft.com/oldnewthing/20210528-00/?p=105259
So I think that may be the simpler solution.
from xlang.
This issue is stale because it has been open 10 days with no activity. Remove stale label or comment or this will be closed in 5 days.
from xlang.
Related Issues (20)
- Toast Notification Callback: Get name of button argument (and input text if possible too) HOT 2
- Build and release winrt package for Python 3.10 HOT 8
- Support methods with default parameters HOT 1
- [Bug] pywinrt Timeline Properties Position Value Incorrect HOT 1
- pywinrt: precompiled header does not improve build time HOT 1
- Please allow arrays in structs (enhancement request) HOT 8
- How to make MIDL3 arrays with "weak" ownership? HOT 5
- Toast Notification without online image HOT 2
- Ability to declare classic COM interfaces from MIDL 3.0 and use it as a projected type HOT 1
- RegFreeWinRT support has bug in string handling that leads to failed DLL lookup
- Python/WinRT wheel file on PiPy for Python 3.10 HOT 2
- UndockedRegFreeWinrt requires the netfx3 feature on demand unnecessarily
- UndockedRegFreeWinRT does no error checking on Detours calls HOT 2
- 【winrt】Failed to import JapanesePhoneticAnalyzer HOT 2
- Undocked regfreewinrt binaries are not included in application when using custom VS build configurations HOT 2
- IObservableVectorView<T> HOT 1
- Ability to have real constants in WinRT HOT 1
- The winrt package is not available for Python v3.10 HOT 1
- Please try [winsdk](https://pypi.org/project/winsdk/) instead of [winrt](https://pypi.org/project/winrt/). HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xlang.