Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 893f834

Browse files
committed
update to PyWinRT 1.0.0-beta.8
1 parent c733f08 commit 893f834

1,268 files changed

Lines changed: 124117 additions & 59490 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Changed
88
- Updated CppWinRT to v2.0.230225.1.
9+
- Update PyWinRT to [v1.0.0-beta.8](https://github.com/pywinrt/pywinrt/releases/tag/v1.0.0-beta.8).
910

1011
## [v1.0.0b7] - 2022-09-09
1112

generate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
param ([switch]$skipNugetInstall)
22

3-
$pywinrt_version = '1.0.0-beta.7'
3+
$pywinrt_version = '1.0.0-beta.8'
44
$cppwinrt_version = '2.0.230225.1'
55
$windows_sdk_version = '10.0.22621.0+'
66
$repoRootPath = (Get-Item $PSScriptRoot).FullName

pywinrt/winsdk/__init__.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

pywinrt/winsdk/_winrt.pyi

Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,9 @@
1-
# WARNING: Please don't edit this file. It was generated by Python/WinRT v1.0.0-beta.7
2-
1+
# WARNING: Please don't edit this file. It was generated by Python/WinRT v1.0.0-beta.8
32

3+
import array
4+
import types
5+
import typing
46
import sys
5-
import uuid
6-
7-
if sys.version_info >= (3, 9):
8-
from typing import Annotated
9-
# type aliases with struct format string annotation
10-
Boolean = Annotated[bool, "?"]
11-
Int8 = Annotated[int, "b"]
12-
UInt8 = Annotated[int, "B"]
13-
Int16 = Annotated[int, "h"]
14-
UInt16 = Annotated[int, "H"]
15-
Int32 = Annotated[int, "i"]
16-
UInt32 = Annotated[int, "I"]
17-
Int64 = Annotated[int, "q"]
18-
UInt64 = Annotated[int, "Q"]
19-
Single = Annotated[float, "f"]
20-
Double = Annotated[float, "d"]
21-
else:
22-
Boolean = bool
23-
Int8 = int
24-
UInt8 = int
25-
Int16 = int
26-
UInt16 = int
27-
Int32 = int
28-
UInt32 = int
29-
Int64 = int
30-
UInt64 = int
31-
Single = float
32-
Double = float
33-
34-
Char16 = UInt16 # Char16 also implies valid UTF-16 codepoint
35-
36-
# WinRT GUIDs are marshaled to Python UUIDs
37-
Guid = uuid.UUID
387

398
MTA: int
409
STA: int
@@ -43,5 +12,66 @@ def init_apartment(apartment_type: int) -> None: ...
4312
def uninit_apartment() -> None: ...
4413
def initialize_with_window(obj: Object, hwnd: int) -> None: ...
4514

46-
class Object:
47-
pass
15+
class Object: ...
16+
17+
_Self = typing.TypeVar("_Self")
18+
_T = typing.TypeVar("_T")
19+
20+
class Array(typing.MutableSequence[_T]):
21+
_winrt_element_type_name_: str
22+
if sys.version_info >= (3, 9):
23+
def __class_getitem__(cls, key: typing.Any) -> types.GenericAlias: ...
24+
25+
@typing.overload
26+
def __new__(
27+
cls: typing.Type[_Self],
28+
__type: typing.Union[typing.Type[_T], str],
29+
__size: int,
30+
/,
31+
) -> _Self: ...
32+
@typing.overload
33+
def __new__(
34+
cls: typing.Type[_Self],
35+
__type: typing.Union[typing.Type[_T], str],
36+
__initializer: memoryview,
37+
/,
38+
) -> _Self: ...
39+
@typing.overload
40+
def __new__(
41+
cls: typing.Type[_Self], __type: str, __initializer: array.array, /
42+
) -> _Self: ...
43+
@typing.overload
44+
def __new__(
45+
cls: typing.Type[_Self],
46+
__type: typing.Union[typing.Type[_T], str],
47+
__initializer: Array[_T],
48+
/,
49+
) -> _Self: ...
50+
@typing.overload
51+
def __new__(
52+
cls: typing.Type[_Self],
53+
__type: typing.Union[typing.Type[_T], str],
54+
__initializer: typing.List[_T],
55+
/,
56+
) -> _Self: ...
57+
@typing.overload
58+
def __new__(
59+
cls: typing.Type[_Self],
60+
__type: typing.Union[typing.Type[_T], str],
61+
__initializer: typing.Tuple[_T],
62+
/,
63+
) -> _Self: ...
64+
def __len__(self) -> int: ...
65+
@typing.overload
66+
def __getitem__(self, index: typing.SupportsIndex) -> _T: ...
67+
@typing.overload
68+
def __getitem__(self, index: slice) -> typing.MutableSequence[_T]: ...
69+
@typing.overload
70+
def __setitem__(self, index: typing.SupportsIndex, value: _T) -> None: ...
71+
@typing.overload
72+
def __setitem__(self, index: slice, value: typing.Iterable[_T]) -> None: ...
73+
@typing.overload
74+
def __delitem__(self, index: typing.SupportsIndex) -> None: ...
75+
@typing.overload
76+
def __delitem__(self, index: slice) -> None: ...
77+
def insert(self, index: typing.SupportsIndex, value: _T) -> None: ...

pywinrt/winsdk/src/_winrt.cpp

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// WARNING: Please don't edit this file. It was generated by Python/WinRT v1.0.0-beta.7
1+
// WARNING: Please don't edit this file. It was generated by Python/WinRT v1.0.0-beta.8
22

33
#include "pybase.h"
44
#include <Shobjidl.h>
@@ -9,6 +9,7 @@ namespace py::cpp::_winrt
99
struct module_state
1010
{
1111
PyTypeObject* Object_type;
12+
PyTypeObject* Array_type;
1213
PyTypeObject* MappingIter_type;
1314
};
1415

@@ -31,7 +32,13 @@ namespace py::cpp::_winrt
3132
py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self)
3233
{
3334
auto tp = Py_TYPE(self);
34-
self->obj = nullptr;
35+
36+
if (PyType_IS_GC(tp))
37+
{
38+
PyObject_GC_UnTrack(self);
39+
}
40+
41+
std::destroy_at(&self->obj);
3542
tp->tp_free(self);
3643
Py_DECREF(tp);
3744
}
@@ -52,6 +59,15 @@ namespace py::cpp::_winrt
5259

5360
// END: class _winrt.Object:
5461

62+
// BEGIN: class _winrt.Array:
63+
64+
extern PyType_Spec Array_type_spec;
65+
#if PY_VERSION_HEX < 0x03090000
66+
extern PyBufferProcs Array_buffer_procs;
67+
#endif
68+
69+
// END: class _winrt.Array:
70+
5571
// BEGIN: class _winrt.MappingIter:
5672

5773
// This class is used to wrap the iterator returned by IMap/IMapView so
@@ -238,6 +254,7 @@ namespace py::cpp::_winrt
238254
assert(state);
239255

240256
Py_VISIT(state->Object_type);
257+
Py_VISIT(state->Array_type);
241258
Py_VISIT(state->MappingIter_type);
242259

243260
return 0;
@@ -249,6 +266,7 @@ namespace py::cpp::_winrt
249266
assert(state);
250267

251268
Py_CLEAR(state->Object_type);
269+
Py_CLEAR(state->Array_type);
252270
Py_CLEAR(state->MappingIter_type);
253271

254272
return 0;
@@ -272,6 +290,29 @@ namespace py::cpp::_winrt
272290
static const auto kSTA
273291
= static_cast<long>(winrt::apartment_type::single_threaded);
274292

293+
py::pyobj_handle collections_abc_module{
294+
PyImport_ImportModule("collections.abc")};
295+
296+
if (!collections_abc_module)
297+
{
298+
return nullptr;
299+
}
300+
301+
py::pyobj_handle mutable_sequence_type{
302+
PyObject_GetAttrString(collections_abc_module.get(), "MutableSequence")};
303+
304+
if (!mutable_sequence_type)
305+
{
306+
return nullptr;
307+
}
308+
309+
py::pyobj_handle array_bases{PyTuple_Pack(1, mutable_sequence_type.get())};
310+
311+
if (!array_bases)
312+
{
313+
return nullptr;
314+
}
315+
275316
py::pyobj_handle module{PyModule_Create(&module_def)};
276317

277318
if (!module)
@@ -283,25 +324,33 @@ namespace py::cpp::_winrt
283324
assert(state);
284325

285326
state->Object_type = py::register_python_type(
286-
module.get(), _type_name_Object, &Object_type_spec, nullptr);
327+
module.get(), _type_name_Object, &Object_type_spec, nullptr, nullptr);
287328

288329
if (!state->Object_type)
289330
{
290331
return nullptr;
291332
}
292333

293-
Py_INCREF(state->Object_type);
334+
state->Array_type = py::register_python_type(
335+
module.get(), "Array", &Array_type_spec, array_bases.get(), nullptr);
336+
337+
if (!state->Array_type)
338+
{
339+
return nullptr;
340+
}
341+
342+
#if PY_VERSION_HEX < 0x03090000
343+
state->Array_type->tp_as_buffer = &Array_buffer_procs;
344+
#endif
294345

295346
state->MappingIter_type = py::register_python_type(
296-
module.get(), "MappingIter", &MappingIter_type_spec, nullptr);
347+
module.get(), "MappingIter", &MappingIter_type_spec, nullptr, nullptr);
297348

298349
if (!state->MappingIter_type)
299350
{
300351
return nullptr;
301352
}
302353

303-
Py_INCREF(state->MappingIter_type);
304-
305354
if (PyModule_AddIntConstant(module.get(), "MTA", kMTA) == -1)
306355
{
307356
return nullptr;
@@ -339,6 +388,24 @@ PyTypeObject* py::winrt_type<py::Object>::get_python_type() noexcept
339388
return state->Object_type;
340389
}
341390

391+
PyTypeObject* py::winrt_type<py::Array>::get_python_type() noexcept
392+
{
393+
// borrowed ref
394+
auto module = PyState_FindModule(&py::cpp::_winrt::module_def);
395+
396+
if (!module)
397+
{
398+
PyErr_SetString(PyExc_RuntimeError, "could not find _winrt module");
399+
return nullptr;
400+
}
401+
402+
auto state
403+
= reinterpret_cast<py::cpp::_winrt::module_state*>(PyModule_GetState(module));
404+
assert(state);
405+
406+
return state->Array_type;
407+
}
408+
342409
PyTypeObject* py::winrt_type<py::MappingIter>::get_python_type() noexcept
343410
{
344411
// borrowed ref

0 commit comments

Comments
 (0)