diff options
author | Cristián Maureira-Fredes <[email protected]> | 2025-07-10 11:41:10 +0200 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2025-07-10 13:01:45 +0000 |
commit | 2809ad352ce5c9088bb5fe767dcfca9999c07bc2 (patch) | |
tree | bf5cf492577c2cc1262bf653225a42474e647b0e | |
parent | f73a5a291cd1a3b6f7bbd3f761435dc468771a31 (diff) |
Avoid using typing.Self due in versions < 3.11
When typing.Self doesn't exist (< 3.11) we were monkey-patching
the attribute to the typing module, in order to use 'typing.Self'
for our constructors stubs.
This was affecting the behavior of another module, that was performing
a similar check on the typing.Self attribute.
Amends 1ef1fefc26038a80ba81a860cff5024db44dca37
Change-Id: I5bacbb3db6a7ecd7c10fcbf08f702172e5163868
Fixes: PYSIDE-3135
Pick-to: 6.9 6.8
Reviewed-by: Friedemann Kleint <[email protected]>
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 3 | ||||
-rw-r--r-- | sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index c057050fd..39d5ad563 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -4979,7 +4979,8 @@ QString CppGenerator::writeCopyFunction(TextStream &s, const QString className = chopType(cpythonTypeName(metaClass)); const QString funcName = className + u"__copy__"_s; - signatureStream << fullPythonClassName(metaClass) << ".__copy__(self)->typing.Self\n"; + // PYSIDE-3135 replace _Self by Self when the minimum Python version is 3.11 + signatureStream << fullPythonClassName(metaClass) << ".__copy__(self)->typing._Self\n"; definitionStream << PyMethodDefEntry{u"__copy__"_s, funcName, {"METH_NOARGS"_ba}, {}} << ",\n"; diff --git a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py index 84cb15feb..74d8a73f1 100644 --- a/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py +++ b/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py @@ -30,11 +30,16 @@ class ellipsis: return "..." +# PYSIDE-3135 +# Using _Self to avoid adding the parameter to typing in versions <3.11 +# Drop this when Python 3.11 is the minimum version if not hasattr(typing, "Self"): @typing._SpecialForm def Self(self, parameters): raise TypeError(f"{self} is not subscriptable") - typing.Self = Self + typing._Self = Self +else: + typing._Self = typing.Self ellipsis = ellipsis() Point = typing.Tuple[int, int] |