Skip to content

Commit

Permalink
Merge pull request #246 from mirumee/mypy_strict_without_optional
Browse files Browse the repository at this point in the history
Mypy strict without optional dependencies
  • Loading branch information
mat-sop authored Dec 4, 2023
2 parents 4cb4af7 + 3c02e01 commit a30d1b0
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 83 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install basic dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -e .[dev]
- name: Mypy strict without optional dependencies
run: |
mypy --strict tests/main/clients/*/expected_client
mypy --strict tests/main/graphql_schemas/*/expected_schema.py
mypy --strict ariadne_codegen/client_generators/dependencies
- name: Install optional dependencies
run: |
pip install -e .[subscriptions,opentelemetry,dev]
- name: Pytest
run: |
Expand All @@ -33,9 +41,10 @@ jobs:
run: |
pylint ariadne_codegen tests
mypy ariadne_codegen --ignore-missing-imports
# these test outputs represent things that may be committed into other projects that may
# have strict mypy settings, and so they should be maximally annotated.
mypy --strict tests/main/clients/*/expected_client
mypy --strict tests/main/graphql_schemas/*/expected_schema.py
black --check .
isort . --check-only
- name: Mypy strict with all dependencies
run: |
mypy --strict tests/main/clients/*/expected_client
mypy --strict tests/main/graphql_schemas/*/expected_schema.py
mypy --strict ariadne_codegen/client_generators/dependencies
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `include_all_inputs` config flag to generate only inputs used in supplied operations.
- Added `include_all_enums` config flag to generate only enums used in supplied operations.
- Added `operationName` to payload sent by generated client's methods.
- Fixed base clients to pass `mypy --strict` without installed optional dependencies.


## 0.10.0 (2023-11-15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -37,26 +44,28 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")


try:
from opentelemetry.trace import ( # type: ignore[attr-defined]
from opentelemetry.context import ( # type: ignore[import-not-found,unused-ignore]
Context,
)
from opentelemetry.trace import ( # type: ignore[import-not-found,unused-ignore]
Span,
Tracer,
get_tracer,
set_span_in_context,
)
except ImportError:
Context = Any # type: ignore
Span = Any # type: ignore
Tracer = Any # type: ignore
Context = Any # type: ignore[misc,assignment,unused-ignore]
Span = Any # type: ignore[misc,assignment,unused-ignore]
Tracer = Any # type: ignore[misc,assignment,unused-ignore]

def get_tracer(*args, **kwargs) -> Tracer: # type: ignore
raise NotImplementedError("Telemetry requires 'opentelemetry-api' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
)

try:
from opentelemetry.trace import ( # type: ignore[attr-defined]
from opentelemetry.context import ( # type: ignore[import-not-found,unused-ignore]
Context,
)
from opentelemetry.trace import ( # type: ignore[import-not-found,unused-ignore]
Span,
Tracer,
get_tracer,
set_span_in_context,
)
except ImportError:
Context = Any # type: ignore
Span = Any # type: ignore
Tracer = Any # type: ignore
Context = Any # type: ignore[misc,assignment,unused-ignore]
Span = Any # type: ignore[misc,assignment,unused-ignore]
Tracer = Any # type: ignore[misc,assignment,unused-ignore]

def get_tracer(*args, **kwargs) -> Tracer: # type: ignore
raise NotImplementedError("Telemetry requires 'opentelemetry-api' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
17 changes: 12 additions & 5 deletions tests/main/clients/example/expected_client/async_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
)

try:
from websockets.client import WebSocketClientProtocol, connect as ws_connect
from websockets.typing import Data, Origin, Subprotocol
from websockets.client import ( # type: ignore[import-not-found,unused-ignore]
WebSocketClientProtocol,
connect as ws_connect,
)
from websockets.typing import ( # type: ignore[import-not-found,unused-ignore]
Data,
Origin,
Subprotocol,
)
except ImportError:
from contextlib import asynccontextmanager

Expand All @@ -26,9 +33,9 @@ async def ws_connect(*args, **kwargs): # pylint: disable=unused-argument
raise NotImplementedError("Subscriptions require 'websockets' package.")
yield # pylint: disable=unreachable

WebSocketClientProtocol = Any # type: ignore
Data = Any # type: ignore
Origin = Any # type: ignore
WebSocketClientProtocol = Any # type: ignore[misc,assignment,unused-ignore]
Data = Any # type: ignore[misc,assignment,unused-ignore]
Origin = Any # type: ignore[misc,assignment,unused-ignore]

def Subprotocol(*args, **kwargs): # type: ignore # pylint: disable=invalid-name
raise NotImplementedError("Subscriptions require 'websockets' package.")
Expand Down
Loading

0 comments on commit a30d1b0

Please sign in to comment.