From 75f90fca980b4ec37e689499f57a7cf7c325498e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20Mat=C3=ADas=20S=C3=A1nchez=20=28Quique=29?= Date: Thu, 8 Sep 2022 15:05:53 +0200 Subject: [PATCH] First steps with static type checking --- Pipfile | 3 + Pipfile.lock | 145 +++++++++++++++++++++++++++++++++++------------ indo/models.py | 7 ++- mypy-django.ini | 2 + mypy.ini | 28 +++++++++ requirements.txt | 52 ++++++++--------- 6 files changed, 172 insertions(+), 65 deletions(-) create mode 100644 mypy-django.ini create mode 100644 mypy.ini diff --git a/Pipfile b/Pipfile index 25274e4..339bf97 100644 --- a/Pipfile +++ b/Pipfile @@ -7,9 +7,12 @@ verify_ssl = true black = "*" coverage = "*" django-debug-toolbar = "*" +django-stubs = "*" +mypy = "*" pre-commit = "*" pylint = "*" rope = "*" +types-bleach = "*" [packages] bleach = {extras = ["css"], version = "*"} diff --git a/Pipfile.lock b/Pipfile.lock index e6f15be..4f1b7f2 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b3f1f4b161682b9da1fd15478a2a11d364e1951766f8cc9eebb8d16483bb2ab9" + "sha256": "d12d7c94bba4bb1798b355245aa006a3329cd5556a56b078dc45e33df10acabc" }, "pipfile-spec": 6, "requires": { @@ -204,31 +204,35 @@ }, "cryptography": { "hashes": [ - "sha256:190f82f3e87033821828f60787cfa42bff98404483577b591429ed99bed39d59", - "sha256:2be53f9f5505673eeda5f2736bea736c40f051a739bfae2f92d18aed1eb54596", - "sha256:30788e070800fec9bbcf9faa71ea6d8068f5136f60029759fd8c3efec3c9dcb3", - "sha256:3d41b965b3380f10e4611dbae366f6dc3cefc7c9ac4e8842a806b9672ae9add5", - "sha256:4c590ec31550a724ef893c50f9a97a0c14e9c851c85621c5650d699a7b88f7ab", - "sha256:549153378611c0cca1042f20fd9c5030d37a72f634c9326e225c9f666d472884", - "sha256:63f9c17c0e2474ccbebc9302ce2f07b55b3b3fcb211ded18a42d5764f5c10a82", - "sha256:6bc95ed67b6741b2607298f9ea4932ff157e570ef456ef7ff0ef4884a134cc4b", - "sha256:7099a8d55cd49b737ffc99c17de504f2257e3787e02abe6d1a6d136574873441", - "sha256:75976c217f10d48a8b5a8de3d70c454c249e4b91851f6838a4e48b8f41eb71aa", - "sha256:7bc997818309f56c0038a33b8da5c0bfbb3f1f067f315f9abd6fc07ad359398d", - "sha256:80f49023dd13ba35f7c34072fa17f604d2f19bf0989f292cedf7ab5770b87a0b", - "sha256:91ce48d35f4e3d3f1d83e29ef4a9267246e6a3be51864a5b7d2247d5086fa99a", - "sha256:a958c52505c8adf0d3822703078580d2c0456dd1d27fabfb6f76fe63d2971cd6", - "sha256:b62439d7cd1222f3da897e9a9fe53bbf5c104fff4d60893ad1355d4c14a24157", - "sha256:b7f8dd0d4c1f21759695c05a5ec8536c12f31611541f8904083f3dc582604280", - "sha256:d204833f3c8a33bbe11eda63a54b1aad7aa7456ed769a982f21ec599ba5fa282", - "sha256:e007f052ed10cc316df59bc90fbb7ff7950d7e2919c9757fd42a2b8ecf8a5f67", - "sha256:f2dcb0b3b63afb6df7fd94ec6fbddac81b5492513f7b0436210d390c14d46ee8", - "sha256:f721d1885ecae9078c3f6bbe8a88bc0786b6e749bf32ccec1ef2b18929a05046", - "sha256:f7a6de3e98771e183645181b3627e2563dcde3ce94a9e42a3f427d2255190327", - "sha256:f8c0a6e9e1dd3eb0414ba320f85da6b0dcbd543126e30fcc546e7372a7fbf3b9" + "sha256:0297ffc478bdd237f5ca3a7dc96fc0d315670bfa099c04dc3a4a2172008a405a", + "sha256:10d1f29d6292fc95acb597bacefd5b9e812099d75a6469004fd38ba5471a977f", + "sha256:16fa61e7481f4b77ef53991075de29fc5bacb582a1244046d2e8b4bb72ef66d0", + "sha256:194044c6b89a2f9f169df475cc167f6157eb9151cc69af8a2a163481d45cc407", + "sha256:1db3d807a14931fa317f96435695d9ec386be7b84b618cc61cfa5d08b0ae33d7", + "sha256:3261725c0ef84e7592597606f6583385fed2a5ec3909f43bc475ade9729a41d6", + "sha256:3b72c360427889b40f36dc214630e688c2fe03e16c162ef0aa41da7ab1455153", + "sha256:3e3a2599e640927089f932295a9a247fc40a5bdf69b0484532f530471a382750", + "sha256:3fc26e22840b77326a764ceb5f02ca2d342305fba08f002a8c1f139540cdfaad", + "sha256:5067ee7f2bce36b11d0e334abcd1ccf8c541fc0bbdaf57cdd511fdee53e879b6", + "sha256:52e7bee800ec869b4031093875279f1ff2ed12c1e2f74923e8f49c916afd1d3b", + "sha256:64760ba5331e3f1794d0bcaabc0d0c39e8c60bf67d09c93dc0e54189dfd7cfe5", + "sha256:765fa194a0f3372d83005ab83ab35d7c5526c4e22951e46059b8ac678b44fa5a", + "sha256:79473cf8a5cbc471979bd9378c9f425384980fcf2ab6534b18ed7d0d9843987d", + "sha256:896dd3a66959d3a5ddcfc140a53391f69ff1e8f25d93f0e2e7830c6de90ceb9d", + "sha256:89ed49784ba88c221756ff4d4755dbc03b3c8d2c5103f6d6b4f83a0fb1e85294", + "sha256:ac7e48f7e7261207d750fa7e55eac2d45f720027d5703cd9007e9b37bbb59ac0", + "sha256:ad7353f6ddf285aeadfaf79e5a6829110106ff8189391704c1d8801aa0bae45a", + "sha256:b0163a849b6f315bf52815e238bc2b2346604413fa7c1601eea84bcddb5fb9ac", + "sha256:b6c9b706316d7b5a137c35e14f4103e2115b088c412140fdbd5f87c73284df61", + "sha256:c2e5856248a416767322c8668ef1845ad46ee62629266f84a8f007a317141013", + "sha256:ca9f6784ea96b55ff41708b92c3f6aeaebde4c560308e5fbbd3173fbc466e94e", + "sha256:d1a5bd52d684e49a36582193e0b89ff267704cd4025abefb9e26803adeb3e5fb", + "sha256:d3971e2749a723e9084dd507584e2a2761f78ad2c638aa31e80bc7a15c9db4f9", + "sha256:d4ef6cc305394ed669d4d9eebf10d3a101059bdcf2669c366ec1d14e4fb227bd", + "sha256:d9e69ae01f99abe6ad646947bba8941e896cb3aa805be2597a0400e0764b5818" ], "markers": "python_version >= '3.6'", - "version": "==37.0.4" + "version": "==38.0.1" }, "cssselect2": { "hashes": [ @@ -778,11 +782,11 @@ }, "astroid": { "hashes": [ - "sha256:396c88d0a58d7f8daadf730b2ce90838bf338c6752558db719ec6f99c18ec20e", - "sha256:d612609242996c4365aeb0345e61edba34363eaaba55f1c0addf6a98f073bef6" + "sha256:0dafbfcf4ebdecd3c8f6d742c9d9c88508229ca823d5c98ab872d964f3321e56", + "sha256:27a22f40e45af6d362498647a0940e8ae9c35f71cb572a1b6f8f810122a11918" ], "markers": "python_full_version >= '3.7.2'", - "version": "==2.12.5" + "version": "==2.12.9" }, "black": { "hashes": [ @@ -916,6 +920,22 @@ "index": "pypi", "version": "==3.6.0" }, + "django-stubs": { + "hashes": [ + "sha256:0dff8ec0ba3abe046450b3d8a29ce9e72629893d2c1ef679189cc2bfdb6d2f64", + "sha256:ea8b35d0da49f7b2ee99a79125f1943e033431dd114726d6643cc35de619230e" + ], + "index": "pypi", + "version": "==1.12.0" + }, + "django-stubs-ext": { + "hashes": [ + "sha256:9bd7418376ab00b7f88d6d56be9fece85bfa0c7c348ac621155fa4d7a91146f2", + "sha256:c5d8db53d29c756e7e3d0820a5a079a43bc38d8fab0e1b8bd5df2f3366c54b5a" + ], + "markers": "python_version >= '3.6'", + "version": "==0.5.0" + }, "filelock": { "hashes": [ "sha256:55447caa666f2198c5b6b13a26d2084d26fa5b115c00d065664b2124680c4edc", @@ -926,11 +946,11 @@ }, "identify": { "hashes": [ - "sha256:25851c8c1370effb22aaa3c987b30449e9ff0cece408f810ae6ce408fdd20893", - "sha256:887e7b91a1be152b0d46bbf072130235a8117392b9f1828446079a816a05ef44" + "sha256:322a5699daecf7c6fd60e68852f36f2ecbb6a36ff6e6e973e0d2bb6fca203ee6", + "sha256:ef78c0d96098a3b5fe7720be4a97e73f439af7cf088ebf47b620aeaa10fadf97" ], "markers": "python_version >= '3.7'", - "version": "==2.5.3" + "version": "==2.5.5" }, "isort": { "hashes": [ @@ -991,6 +1011,35 @@ "markers": "python_version >= '3.6'", "version": "==0.7.0" }, + "mypy": { + "hashes": [ + "sha256:02ef476f6dcb86e6f502ae39a16b93285fef97e7f1ff22932b657d1ef1f28655", + "sha256:0d054ef16b071149917085f51f89555a576e2618d5d9dd70bd6eea6410af3ac9", + "sha256:19830b7dba7d5356d3e26e2427a2ec91c994cd92d983142cbd025ebe81d69cf3", + "sha256:1f7656b69974a6933e987ee8ffb951d836272d6c0f81d727f1d0e2696074d9e6", + "sha256:23488a14a83bca6e54402c2e6435467a4138785df93ec85aeff64c6170077fb0", + "sha256:23c7ff43fff4b0df93a186581885c8512bc50fc4d4910e0f838e35d6bb6b5e58", + "sha256:25c5750ba5609a0c7550b73a33deb314ecfb559c350bb050b655505e8aed4103", + "sha256:2ad53cf9c3adc43cf3bea0a7d01a2f2e86db9fe7596dfecb4496a5dda63cbb09", + "sha256:3fa7a477b9900be9b7dd4bab30a12759e5abe9586574ceb944bc29cddf8f0417", + "sha256:40b0f21484238269ae6a57200c807d80debc6459d444c0489a102d7c6a75fa56", + "sha256:4b21e5b1a70dfb972490035128f305c39bc4bc253f34e96a4adf9127cf943eb2", + "sha256:5a361d92635ad4ada1b1b2d3630fc2f53f2127d51cf2def9db83cba32e47c856", + "sha256:77a514ea15d3007d33a9e2157b0ba9c267496acf12a7f2b9b9f8446337aac5b0", + "sha256:855048b6feb6dfe09d3353466004490b1872887150c5bb5caad7838b57328cc8", + "sha256:9796a2ba7b4b538649caa5cecd398d873f4022ed2333ffde58eaf604c4d2cb27", + "sha256:98e02d56ebe93981c41211c05adb630d1d26c14195d04d95e49cd97dbc046dc5", + "sha256:b793b899f7cf563b1e7044a5c97361196b938e92f0a4343a5d27966a53d2ec71", + "sha256:d1ea5d12c8e2d266b5fb8c7a5d2e9c0219fedfeb493b7ed60cd350322384ac27", + "sha256:d2022bfadb7a5c2ef410d6a7c9763188afdb7f3533f22a0a32be10d571ee4bbe", + "sha256:d3348e7eb2eea2472db611486846742d5d52d1290576de99d59edeb7cd4a42ca", + "sha256:d744f72eb39f69312bc6c2abf8ff6656973120e2eb3f3ec4f758ed47e414a4bf", + "sha256:ef943c72a786b0f8d90fd76e9b39ce81fb7171172daf84bf43eaf937e9f220a9", + "sha256:f2899a3cbd394da157194f913a931edfd4be5f274a88041c9dc2d9cdcb1c315c" + ], + "index": "pypi", + "version": "==0.971" + }, "mypy-extensions": { "hashes": [ "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d", @@ -1040,11 +1089,11 @@ }, "pylint": { "hashes": [ - "sha256:4b124affc198b7f7c9b5f9ab690d85db48282a025ef9333f51d2d7281b92a6c3", - "sha256:4f3f7e869646b0bd63b3dfb79f3c0f28fc3d2d923ea220d52620fd625aed92b0" + "sha256:cc3da458ba810c49d330e09013dec7ced5217772dec8f043ccdd34dae648fde8", + "sha256:f63404a2547edb5247da263748771ac9a806ed1de4174cda01293c08ddbc2999" ], "index": "pypi", - "version": "==2.15.0" + "version": "==2.15.2" }, "pyparsing": { "hashes": [ @@ -1149,21 +1198,43 @@ "markers": "python_version >= '3.6' and python_version < '4.0'", "version": "==0.11.4" }, + "types-bleach": { + "hashes": [ + "sha256:5931525d03571f36b2bb40210c34b662c4d26c8fd6f2b1e1e83fe4d2d2fd63c7", + "sha256:f7b3df8278efe176d9670d0f063a66c866c77577f71f54b9c7a320e31b1a7bbd" + ], + "index": "pypi", + "version": "==5.0.3" + }, + "types-pytz": { + "hashes": [ + "sha256:47cfb19c52b9f75896440541db392fd312a35b279c6307a531db71152ea63e2b", + "sha256:50ead2254b524a3d4153bc65d00289b66898060d2938e586170dce918dbaf3b3" + ], + "version": "==2022.2.1.0" + }, + "types-pyyaml": { + "hashes": [ + "sha256:7f7da2fd11e9bc1e5e9eb3ea1be84f4849747017a59fc2eee0ea34ed1147c2e0", + "sha256:8f890028123607379c63550179ddaec4517dc751f4c527a52bb61934bf495989" + ], + "version": "==6.0.11" + }, "typing-extensions": { "hashes": [ "sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02", "sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6" ], - "markers": "python_version < '3.10'", + "markers": "python_version >= '3.7'", "version": "==4.3.0" }, "virtualenv": { "hashes": [ - "sha256:014f766e4134d0008dcaa1f95bafa0fb0f575795d07cae50b1bee514185d6782", - "sha256:035ed57acce4ac35c82c9d8802202b0e71adac011a511ff650cbcf9635006a22" + "sha256:227ea1b9994fdc5ea31977ba3383ef296d7472ea85be9d6732e42a91c04e80da", + "sha256:d07dfc5df5e4e0dbc92862350ad87a36ed505b978f6c39609dc489eadd5b0d27" ], "markers": "python_version >= '3.6'", - "version": "==20.16.4" + "version": "==20.16.5" }, "wrapt": { "hashes": [ diff --git a/indo/models.py b/indo/models.py index 2219359..c49634e 100644 --- a/indo/models.py +++ b/indo/models.py @@ -1,4 +1,7 @@ import datetime + +from typing import Optional + from django.core.validators import FileExtensionValidator from django.db import connection, models from django.urls import reverse @@ -658,7 +661,7 @@ def get_absolute_url(self): def en_borrador(self): return self.estado == 'BORRADOR' - def get_pp_coordinador_or_none(self, tipo): + def get_pp_coordinador_or_none(self, tipo) -> Optional[ParticipanteProyecto]: """Busca el coordinador o coordinador_2 del proyecto""" try: return self.participantes.get(tipo_participacion_id=tipo) @@ -796,7 +799,7 @@ def get_up_gastos(cls, anyo): datos_proyectos.insert(0, cabeceras) return datos_proyectos - def get_unidad_planificacion(self): + def get_unidad_planificacion(self) -> Optional[str]: """Devuelve el ID de la Unidad de Planificación del proyecto PIEC, PIPOUZ, PIET: UP del centro del proyecto diff --git a/mypy-django.ini b/mypy-django.ini new file mode 100644 index 0000000..d83063d --- /dev/null +++ b/mypy-django.ini @@ -0,0 +1,2 @@ +[mypy_django_plugin] +ignore_missing_model_attributes = True diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..2f5ee58 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,28 @@ +[mypy] +# The mypy configuration file: +python_version = 3.10 + +check_untyped_defs = True +# disallow_any_explicit = True +disallow_any_generics = True +disallow_untyped_calls = True +disallow_untyped_decorators = True +ignore_errors = False +ignore_missing_imports = True +implicit_reexport = False +strict_optional = True +strict_equality = True +no_implicit_optional = True +warn_unused_ignores = True +warn_redundant_casts = True +warn_unused_configs = True +warn_unreachable = True +warn_no_return = True + +plugins = mypy_django_plugin.main + +[mypy.plugins.django-stubs] +django_settings_module = manhattan_project.settings + +[mypy-*.migrations.*] +ignore_errors = True diff --git a/requirements.txt b/requirements.txt index de44871..b4d9006 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,55 +1,55 @@ -i https://pypi.org/simple -asgiref==3.5.2 -attrs==22.1.0 +asgiref==3.5.2; python_version >= '3.7' +attrs==22.1.0; python_version >= '3.5' bleach[css]==5.0.1 brotli==1.0.9 cached-property==1.5.2 -certifi==2022.6.15 +certifi==2022.6.15; python_version >= '3.6' cffi==1.15.1 -charset-normalizer==2.1.1 -cryptography==37.0.4 -cssselect2==0.6.0 -defusedxml==0.7.1 +charset-normalizer==2.1.1; python_version >= '3.6' +cryptography==38.0.1; python_version >= '3.6' +cssselect2==0.6.0; python_version >= '3.7' +defusedxml==0.7.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' django==4.1.1 django-annoying==0.10.6 django-crispy-forms==1.14.0 django-filter==22.1 -django-render-block==0.9.1 +django-render-block==0.9.1; python_version >= '3.6' django-summernote==0.8.20.0 django-tables2==2.4.1 django-templated-email==3.0.0 -fonttools[woff]==4.37.1 -html5lib==1.1 +fonttools[woff]==4.37.1; python_version >= '3.7' +html5lib==1.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' huey==2.4.3 -idna==3.3 +idna==3.3; python_version >= '3.5' isodate==0.6.1 -lxml==4.6.5 +lxml==4.6.5; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' mysqlclient==2.1.1 -oauthlib==3.2.0 -pillow==9.2.0 -platformdirs==2.5.2 -pycparser==2.21 -pydyf==0.2.0 -pyjwt==2.4.0 +oauthlib==3.2.0; python_version >= '3.6' +pillow==9.2.0; python_version >= '3.7' +platformdirs==2.5.2; python_version >= '3.7' +pycparser==2.21; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' +pydyf==0.2.0; python_version >= '3.7' +pyjwt==2.4.0; python_version >= '3.6' pypandoc==1.8.1 -pyphen==0.13.0 +pyphen==0.13.0; python_version >= '3.7' python-magic==0.4.27 python3-openid==3.2.0 python3-saml==1.14.0 pytz==2022.2.1 -requests==2.28.1 +requests==2.28.1; python_version >= '3.7' and python_version < '4' requests-file==1.5.1 -requests-oauthlib==1.3.1 +requests-oauthlib==1.3.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' requests-toolbelt==0.9.1 -six==1.16.0 +six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' social-auth-app-django==5.0.0 social-auth-core[saml]==4.3.0 -sqlparse==0.4.2 +sqlparse==0.4.2; python_version >= '3.5' tablib==3.2.1 -tinycss2==1.1.1 -urllib3==1.26.12 +tinycss2==1.1.1; python_version >= '3.6' +urllib3==1.26.12; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5' and python_version < '4' weasyprint==56.1 webencodings==0.5.1 -xmlsec==1.3.13 +xmlsec==1.3.13; python_version >= '3.5' zeep==4.1.0 zopfli==0.2.1