diff options
| author | Ece Cinucen <ece.cinucen@qt.io> | 2025-02-19 15:52:51 +0100 |
|---|---|---|
| committer | Ece Cinucen <ece.cinucen@qt.io> | 2025-02-27 17:02:21 +0100 |
| commit | 00a5b350ec3d6f552ad0753d9c8fdbde4464d9ad (patch) | |
| tree | c2eaad1be907faaa4e4797f0eca054ccfda829d5 /sources | |
| parent | f351f1e572d2712c735a361b08e45eeb4149f25f (diff) | |
Improve type annotations, first step
Import Callable, Iterable and Sequence from collections.abc,
since using them from typing is deprecated.
Pick-to: 6.8
Task-number: PYSIDE-3012
Change-Id: I131c00005df410fdaa40b338a2a728512269aaa0
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
9 files changed, 34 insertions, 31 deletions
diff --git a/sources/pyside6/libpyside/class_property.cpp b/sources/pyside6/libpyside/class_property.cpp index 9be7dccb0..cebbd14ca 100644 --- a/sources/pyside6/libpyside/class_property.cpp +++ b/sources/pyside6/libpyside/class_property.cpp @@ -153,13 +153,13 @@ namespace PySide::ClassProperty { static const char *PyClassProperty_SignatureStrings[] = { "PySide6.QtCore.PyClassProperty(cls," - "fget:typing.Optional[typing.Callable[[typing.Any],typing.Any]]=None," - "fset:typing.Optional[typing.Callable[[typing.Any,typing.Any],None]]=None," - "fdel:typing.Optional[typing.Callable[[typing.Any],None]]=None," + "fget:typing.Optional[collections.abc.Callable[[typing.Any],typing.Any]]=None," + "fset:typing.Optional[collections.abc.Callable[[typing.Any,typing.Any],None]]=None," + "fdel:typing.Optional[collections.abc.Callable[[typing.Any],None]]=None," "doc:typing.Optional[str]=None)", - "PySide6.QtCore.PyClassProperty.getter(cls,fget:typing.Callable[[typing.Any],typing.Any])->PySide6.QtCore.PyClassProperty", - "PySide6.QtCore.PyClassProperty.setter(cls,fset:typing.Callable[[typing.Any,typing.Any],None])->PySide6.QtCore.PyClassProperty", - "PySide6.QtCore.PyClassProperty.deleter(cls,fdel:typing.Callable[[typing.Any],None])->PySide6.QtCore.PyClassProperty", + "PySide6.QtCore.PyClassProperty.getter(cls,fget:collections.abc.Callable[[typing.Any],typing.Any])->PySide6.QtCore.PyClassProperty", + "PySide6.QtCore.PyClassProperty.setter(cls,fset:collections.abc.Callable[[typing.Any,typing.Any],None])->PySide6.QtCore.PyClassProperty", + "PySide6.QtCore.PyClassProperty.deleter(cls,fdel:collections.abc.Callable[[typing.Any],None])->PySide6.QtCore.PyClassProperty", nullptr}; // Sentinel void init(PyObject *module) diff --git a/sources/pyside6/libpyside/pysideproperty.cpp b/sources/pyside6/libpyside/pysideproperty.cpp index 7c0400051..84d6be2d2 100644 --- a/sources/pyside6/libpyside/pysideproperty.cpp +++ b/sources/pyside6/libpyside/pysideproperty.cpp @@ -471,19 +471,19 @@ namespace PySide::Property { static const char *Property_SignatureStrings[] = { "PySide6.QtCore.Property(self,type:type," - "fget:typing.Optional[typing.Callable[[typing.Any],typing.Any]]," - "fset:typing.Optional[typing.Callable[[typing.Any,typing.Any],None]]," - "freset:typing.Optional[typing.Callable[[typing.Any,typing.Any],None]]," + "fget:typing.Optional[collections.abc.Callable[[typing.Any],typing.Any]]," + "fset:typing.Optional[collections.abc.Callable[[typing.Any,typing.Any],None]]," + "freset:typing.Optional[collections.abc.Callable[[typing.Any,typing.Any],None]]," "doc:str=None," - "notify:typing.Optional[typing.Callable[[],None]]," + "notify:typing.Optional[collections.abc.Callable[[],None]]," "designable:bool=True,scriptable:bool=True," "stored:bool=True,user:bool=False,constant:bool=False,final:bool=False)", - "PySide6.QtCore.Property.deleter(self,fdel:typing.Callable[[typing.Any],None])->PySide6.QtCore.Property", - "PySide6.QtCore.Property.getter(self,fget:typing.Callable[[typing.Any],typing.Any])->PySide6.QtCore.Property", - "PySide6.QtCore.Property.read(self,fget:typing.Callable[[typing.Any],typing.Any])->PySide6.QtCore.Property", - "PySide6.QtCore.Property.setter(self,fset:typing.Callable[[typing.Any,typing.Any],None])->PySide6.QtCore.Property", - "PySide6.QtCore.Property.write(self,fset:typing.Callable[[typing.Any,typing.Any],None])->PySide6.QtCore.Property", - "PySide6.QtCore.Property.__call__(self, func:typing.Callable[...,typing.Any])->PySide6.QtCore.Property", + "PySide6.QtCore.Property.deleter(self,fdel:collections.abc.Callable[[typing.Any],None])->PySide6.QtCore.Property", + "PySide6.QtCore.Property.getter(self,fget:collections.abc.Callable[[typing.Any],typing.Any])->PySide6.QtCore.Property", + "PySide6.QtCore.Property.read(self,fget:collections.abc.Callable[[typing.Any],typing.Any])->PySide6.QtCore.Property", + "PySide6.QtCore.Property.setter(self,fset:collections.abc.Callable[[typing.Any,typing.Any],None])->PySide6.QtCore.Property", + "PySide6.QtCore.Property.write(self,fset:collections.abc.Callable[[typing.Any,typing.Any],None])->PySide6.QtCore.Property", + "PySide6.QtCore.Property.__call__(self, func:collections.abc.Callable[...,typing.Any])->PySide6.QtCore.Property", nullptr}; // Sentinel void init(PyObject *module) diff --git a/sources/pyside6/libpyside/pysideslot.cpp b/sources/pyside6/libpyside/pysideslot.cpp index 135f83b1e..eddbf3a93 100644 --- a/sources/pyside6/libpyside/pysideslot.cpp +++ b/sources/pyside6/libpyside/pysideslot.cpp @@ -168,7 +168,7 @@ DataList *dataListFromCapsule(PyObject *capsule) static const char *Slot_SignatureStrings[] = { "PySide6.QtCore.Slot(self,*types:type,name:str=nullptr,result:type=nullptr)", - "PySide6.QtCore.Slot.__call__(self,function:typing.Callable[...,typing.Any])->typing.Any", + "PySide6.QtCore.Slot.__call__(self,function:collections.abc.Callable[...,typing.Any])->typing.Any", nullptr}; // Sentinel void init(PyObject *module) diff --git a/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp b/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp index 447d16564..591e36683 100644 --- a/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp +++ b/sources/pyside6/libpysideqml/pysideqmllistproperty.cpp @@ -281,10 +281,10 @@ void QmlListPropertyPrivate::metaCall(PyObject *source, QMetaObject::Call call, static const char *PropertyList_SignatureStrings[] = { "PySide6.QtQml.ListProperty(self,type:type," - "append:typing.Optional[typing.Callable[...,typing.Any]]=None," - "at:typing.Optional[typing.Callable[...,typing.Any]]=None," - "clear:typing.Optional[typing.Callable[...,typing.Any]]=None," - "count:typing.Optional[typing.Callable[...,typing.Any]]=None)", + "append:typing.Optional[collections.abc.Callable[...,typing.Any]]=None," + "at:typing.Optional[collections.abc.Callable[...,typing.Any]]=None," + "clear:typing.Optional[collections.abc.Callable[...,typing.Any]]=None," + "count:typing.Optional[collections.abc.Callable[...,typing.Any]]=None)", nullptr // Sentinel }; diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py index 72de1516e..0397d77f9 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/enum_sig.py @@ -15,7 +15,7 @@ by producing a lot of clarity. import inspect import sys import types -import typing +import collections from shibokensupport.signature import get_signature as get_sig from shibokensupport.signature.layout import DEFAULT_PARAM_KIND from enum import Enum @@ -285,7 +285,7 @@ class ExactEnumerator: # PYSIDE-2846: Special cases of signatures which inherit from object. _self = inspect.Parameter("self", DEFAULT_PARAM_KIND) if func_name == "__dir__": - signature = inspect.Signature([_self], return_annotation=typing.Iterable[str]) + signature = inspect.Signature([_self], return_annotation=collections.abc.Iterable[str]) elif func_name == "__repr__": signature = inspect.Signature([_self], return_annotation=str) if signature is not None: diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/pyi_generator.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/pyi_generator.py index 71dcea5a6..7f1bdfbed 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/pyi_generator.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/pyi_generator.py @@ -227,7 +227,7 @@ FROM_IMPORTS = [ (None, ["os"]), (None, ["enum"]), (None, ["typing"]), - ("collections.abc", ["Iterable"]), + (None, ["collections"]), ("PySide6.QtCore", ["PyClassProperty", "Signal", "SignalInstance"]), ("shiboken6", ["Shiboken"]), ] diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index af0fc6c0a..995d0176a 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -18,6 +18,7 @@ import os import struct import sys import typing +import collections from pathlib import Path from typing import TypeVar, Generic @@ -38,7 +39,7 @@ if not hasattr(typing, "Self"): ellipsis = ellipsis() Point = typing.Tuple[int, int] Variant = typing.Any -QImageCleanupFunction = typing.Callable[..., typing.Any] +QImageCleanupFunction = collections.abc.Callable[..., typing.Any] # unfortunately, typing.Optional[t] expands to typing.Union[t, NoneType] # Until we can force it to create Optional[t] again, we use this. @@ -223,16 +224,16 @@ type_map.update({ "int": int, "List": ArrayLikeVariable, "Optional": typing.Optional, - "Iterable": typing.Iterable, + "Iterable": collections.abc.Iterable, "long": int, "long long": int, "nullptr": None, - "PyCallable": typing.Callable[..., typing.Any], + "PyCallable": collections.abc.Callable[..., typing.Any], "PyObject": object, "PyObject*": object, "PyArrayObject": ArrayLikeVariable(typing.Any), # numpy "PyPathLike": typing.Union[str, bytes, os.PathLike[str]], - "PySequence": typing.Iterable, # important for numpy + "PySequence": collections.abc.Iterable, # important for numpy "PyTypeObject": type, "QChar": str, "QHash": typing.Dict, diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py index b170d63d6..cc5bbe15a 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/parser.py @@ -10,6 +10,7 @@ import re import sys import typing import warnings +import collections.abc import abc from types import SimpleNamespace @@ -415,7 +416,7 @@ def handle_argvar(obj): Currently, the best approximation is types.Sequence. We want to change that to types.Iterable in the near future. """ - return _handle_generic(obj, typing.Sequence) + return _handle_generic(obj, collections.abc.Sequence) def handle_retvar(obj): @@ -495,7 +496,7 @@ def fix_variables(props, line): for idx, name in enumerate(varnames): ann = safe_annos[name] if isinstance(ann, ArrayLikeVariable): - ann = typing.Sequence[ann.type] + ann = collections.abc.Sequence[ann.type] annos[name] = ann if not isinstance(ann, ResultVariable): continue diff --git a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py index 4bfe125cd..b3e235688 100644 --- a/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py +++ b/sources/shiboken6/tests/samplebinding/pointerprimitivetype_test.py @@ -31,6 +31,7 @@ from sample import IntArray2, VirtualMethods from shibokensupport.signature import get_signature import typing +import collections class PointerPrimitiveTypeTest(unittest.TestCase): @@ -45,7 +46,7 @@ class PointerPrimitiveTypeTest(unittest.TestCase): self.assertTrue(found) ann = sig.parameters["data"].annotation self.assertEqual(ann.__args__, (int,)) - self.assertTrue(issubclass(ann.__origin__, typing.Iterable)) + self.assertTrue(issubclass(ann.__origin__, collections.abc.Iterable)) def testReturnVarSignature(self): # signature="getMargins(int*,int*,int*,int*)const"> |
