From b0bfeaf894344e31b5175dbbd3ce371fae5dee5b Mon Sep 17 00:00:00 2001 From: Christian Tismer Date: Thu, 16 Apr 2020 17:23:55 +0200 Subject: Support type checking with the mypy module According to PEP 561, there needs to exist a py.typed file. Also, the import of typing must be visible statically for mypy without importing PySide2. Testing.. run mypy pyside_1100.py and you will get the correct output without "any". Change-Id: I1d08447161630a8c7a64eda32ff8a431e994c6a7 Fixes: PYSIDE-1100 Reviewed-by: Friedemann Kleint Reviewed-by: Cristian Maureira-Fredes --- sources/pyside2/PySide2/CMakeLists.txt | 3 +++ sources/pyside2/PySide2/py.typed.in | 1 + sources/pyside2/PySide2/support/generate_pyi.py | 4 ++++ 3 files changed, 8 insertions(+) create mode 100644 sources/pyside2/PySide2/py.typed.in (limited to 'sources/pyside2/PySide2') diff --git a/sources/pyside2/PySide2/CMakeLists.txt b/sources/pyside2/PySide2/CMakeLists.txt index e39db75a1..aa37f19bc 100644 --- a/sources/pyside2/PySide2/CMakeLists.txt +++ b/sources/pyside2/PySide2/CMakeLists.txt @@ -8,6 +8,9 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" "${CMAKE_CURRENT_BINARY_DIR}/__init__.py" @ONLY) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/_config.py.in" "${CMAKE_CURRENT_BINARY_DIR}/_config.py" @ONLY) +# typing support for mypy +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/py.typed.in" + "${CMAKE_CURRENT_BINARY_DIR}/py.typed" @ONLY) # Use absolute path instead of relative path, to avoid ninja build errors due to # duplicate file dependency inconsistency. diff --git a/sources/pyside2/PySide2/py.typed.in b/sources/pyside2/PySide2/py.typed.in new file mode 100644 index 000000000..0e76a07dc --- /dev/null +++ b/sources/pyside2/PySide2/py.typed.in @@ -0,0 +1 @@ +# this is a marker file for mypy diff --git a/sources/pyside2/PySide2/support/generate_pyi.py b/sources/pyside2/PySide2/support/generate_pyi.py index e60645701..f173ec2fc 100644 --- a/sources/pyside2/PySide2/support/generate_pyi.py +++ b/sources/pyside2/PySide2/support/generate_pyi.py @@ -138,6 +138,10 @@ class Formatter(Writer): self.print("# Module", mod_name) self.print("import PySide2") from PySide2.support.signature import typing + self.print("try:") + self.print(" import typing") + self.print("except ImportError:") + self.print(" from PySide2.support.signature import typing") self.print("from PySide2.support.signature import typing") self.print("from PySide2.support.signature.mapping import (") self.print(" Virtual, Missing, Invalid, Default, Instance)") -- cgit v1.2.3