From 5f19f229187a8c68f44b61b788d3d8a4ac5175f3 Mon Sep 17 00:00:00 2001 From: Mark Dawson Date: Tue, 17 Oct 2023 10:30:10 +0100 Subject: [PATCH 1/5] added flake8-type-checking --- cylc/uiserver/handlers.py | 5 +++-- setup.cfg | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cylc/uiserver/handlers.py b/cylc/uiserver/handlers.py index 0ec9341e..90a242e8 100644 --- a/cylc/uiserver/handlers.py +++ b/cylc/uiserver/handlers.py @@ -38,10 +38,11 @@ ) from cylc.uiserver.authorise import Authorization, AuthorizationMiddleware -from cylc.uiserver.resolvers import Resolvers from cylc.uiserver.websockets import authenticated as websockets_authenticated -from cylc.uiserver.websockets.tornado import TornadoSubscriptionServer + if TYPE_CHECKING: + from cylc.uiserver.resolvers import Resolvers + from cylc.uiserver.websockets.tornado import TornadoSubscriptionServer from graphql.execution import ExecutionResult diff --git a/setup.cfg b/setup.cfg index 6195c3c3..de096fea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -93,6 +93,7 @@ tests = flake8-debugger>=4.0.0 flake8-mutable>=1.2.0 flake8-simplify>=0.14.0 + flake8-type-checking; python_version > "3.7" flake8>=3.0.0 jupyter_server[test] mypy>=0.900 From 6c0e600fb3de4f6b4d3540cdd9495c2f2cdaa967 Mon Sep 17 00:00:00 2001 From: Mark Dawson Date: Tue, 17 Oct 2023 13:30:29 +0100 Subject: [PATCH 2/5] fix type checking test fails --- cylc/uiserver/handlers.py | 2 +- mypy.ini | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cylc/uiserver/handlers.py b/cylc/uiserver/handlers.py index 90a242e8..5ff573b2 100644 --- a/cylc/uiserver/handlers.py +++ b/cylc/uiserver/handlers.py @@ -98,7 +98,7 @@ def is_token_authenticated(handler: 'CylcAppHandler') -> bool: In these cases the bearer of the token is awarded full privileges. """ identity_provider: JPSIdentityProvider = ( - handler.serverapp.identity_provider + handler.serverapp.identity_provider # type: ignore ) return identity_provider.__class__ == PasswordIdentityProvider # NOTE: not using isinstance to narrow this down to just the one class diff --git a/mypy.ini b/mypy.ini index 72700dda..060c7e52 100644 --- a/mypy.ini +++ b/mypy.ini @@ -14,3 +14,7 @@ explicit_package_bases = True allow_redefinition = True strict_equality = True show_error_codes = True + +# Suppress the following messages: +# By default the bodies of untyped functions are not checked, consider using --check-untyped-defs +disable_error_code = annotation-unchecked \ No newline at end of file From ae22e849bc1924e1cee1758ced2e7ae328924a96 Mon Sep 17 00:00:00 2001 From: Mark Dawson Date: Tue, 17 Oct 2023 13:33:31 +0100 Subject: [PATCH 3/5] removed comment --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index de096fea..a0f5a39d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -93,7 +93,7 @@ tests = flake8-debugger>=4.0.0 flake8-mutable>=1.2.0 flake8-simplify>=0.14.0 - flake8-type-checking; python_version > "3.7" + flake8-type-checking flake8>=3.0.0 jupyter_server[test] mypy>=0.900 From aedebd71864e38a4477658c65595bd28bd6439b7 Mon Sep 17 00:00:00 2001 From: Mark Dawson Date: Tue, 17 Oct 2023 13:35:49 +0100 Subject: [PATCH 4/5] correct flak8 error --- cylc/uiserver/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cylc/uiserver/handlers.py b/cylc/uiserver/handlers.py index 5ff573b2..d7519bfb 100644 --- a/cylc/uiserver/handlers.py +++ b/cylc/uiserver/handlers.py @@ -98,7 +98,7 @@ def is_token_authenticated(handler: 'CylcAppHandler') -> bool: In these cases the bearer of the token is awarded full privileges. """ identity_provider: JPSIdentityProvider = ( - handler.serverapp.identity_provider # type: ignore + handler.serverapp.identity_provider # type: ignore ) return identity_provider.__class__ == PasswordIdentityProvider # NOTE: not using isinstance to narrow this down to just the one class From 82681cc706945f24d33abc76db9333b92ab209c5 Mon Sep 17 00:00:00 2001 From: Mark Dawson Date: Tue, 17 Oct 2023 13:53:01 +0100 Subject: [PATCH 5/5] Added specificity to type ignore --- cylc/uiserver/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cylc/uiserver/handlers.py b/cylc/uiserver/handlers.py index d7519bfb..b20f2a71 100644 --- a/cylc/uiserver/handlers.py +++ b/cylc/uiserver/handlers.py @@ -98,7 +98,7 @@ def is_token_authenticated(handler: 'CylcAppHandler') -> bool: In these cases the bearer of the token is awarded full privileges. """ identity_provider: JPSIdentityProvider = ( - handler.serverapp.identity_provider # type: ignore + handler.serverapp.identity_provider # type: ignore[union-attr] ) return identity_provider.__class__ == PasswordIdentityProvider # NOTE: not using isinstance to narrow this down to just the one class