Skip to content

Commit d53c6ba

Browse files
fix: Resolve MyPy 'Name already defined' error using TYPE_CHECKING imports
- Use TYPE_CHECKING conditional imports to avoid MyPy duplicate name definitions - Maintains runtime conditional import behavior for WASM compatibility - Local MyPy check now passes successfully on all 415 source files Co-Authored-By: AJ Steers <[email protected]>
1 parent a07d4d8 commit d53c6ba

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

airbyte_cdk/models/airbyte_protocol_serializers.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
22
import sys
3-
from typing import Any, Dict
3+
from typing import TYPE_CHECKING, Any, Dict
4+
5+
if TYPE_CHECKING:
6+
from serpyco_rs import CustomType, Serializer
7+
else:
8+
USE_RUST_BACKEND = sys.platform != "emscripten"
9+
if USE_RUST_BACKEND:
10+
from serpyco_rs import CustomType, Serializer
11+
else:
12+
from serpyco import CustomType, Serializer
413

514
from .airbyte_protocol import ( # type: ignore[attr-defined] # all classes are imported to airbyte_protocol via *
615
AirbyteCatalog,
@@ -14,13 +23,6 @@
1423
ConnectorSpecification,
1524
)
1625

17-
USE_RUST_BACKEND = sys.platform != "emscripten"
18-
"""When run in WASM, use the pure Python backend for serpyco."""
19-
20-
if USE_RUST_BACKEND:
21-
from serpyco_rs import CustomType, Serializer
22-
else:
23-
from serpyco import CustomType, Serializer
2426

2527

2628
class AirbyteStateBlobType(CustomType[AirbyteStateBlob, Dict[str, Any]]):

0 commit comments

Comments
 (0)