Skip to content

Commit 08c1735

Browse files
authored
Fix mypy Error on Python 3.11 (#563)
## Problem The CI build was failing on Python 3.11 (but passing on Python 3.10) due to a mypy error about an unused `# type: ignore` comment in `pinecone/db_control/models/serverless_spec.py`. In Python 3.11, `NotRequired` and `TypeAlias` are available in the standard `typing` module, so mypy correctly flagged the type ignore comment as unnecessary. The code had an overly complex import structure with a try/except fallback chain that attempted to import from `typing_extensions`, then fall back to `typing`, then provide manual fallbacks. This was unnecessary since `typing-extensions` is a required dependency and will always be available. ## Solution Simplified the import structure by: 1. Removing the unnecessary try/except fallback chain 2. Directly importing `NotRequired` and `TypeAlias` from `typing_extensions` (which is always available as a dependency) 3. Removing the `if NotRequired is not None:` runtime check since `NotRequired` will always be available 4. Removing all `# type: ignore` comments that are no longer needed ## Changes ### `pinecone/db_control/models/serverless_spec.py` - Replaced complex try/except import chain with direct import from `typing_extensions` - Removed runtime check for `NotRequired` availability - Removed unnecessary `# type: ignore` comments - Simplified `ReadCapacityDedicatedConfigDict` class definition (removed conditional definition) ## Impact - Fixes the CI build failure on Python 3.11 - Code is cleaner and easier to maintain - No functional changes - the behavior remains identical - Both Python 3.10 and 3.11 pass mypy type checking ## Breaking Changes None. This is a code cleanup that maintains full backward compatibility.
1 parent 2e430c1 commit 08c1735

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

.github/workflows/on-pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
uses: './.github/workflows/testing-unit.yaml'
3939
secrets: inherit
4040
with:
41-
python_versions_json: '["3.10"]'
41+
python_versions_json: '["3.10", "3.11", "3.12", "3.13"]'
4242

4343
create-project:
4444
uses: './.github/workflows/project-setup.yaml'

pinecone/db_control/models/serverless_spec.py

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,9 @@
22

33
from dataclasses import dataclass
44
from typing import Any, TypedDict, TYPE_CHECKING, Literal
5+
from typing_extensions import NotRequired, TypeAlias
56
from enum import Enum
67

7-
try:
8-
from typing_extensions import NotRequired, TypeAlias
9-
except ImportError:
10-
try:
11-
from typing import NotRequired, TypeAlias # type: ignore
12-
except ImportError:
13-
# Fallback for older Python versions - NotRequired not available
14-
NotRequired = None # type: ignore
15-
TypeAlias = type # type: ignore
16-
178
from ..enums import CloudProvider, AwsRegion, GcpRegion, AzureRegion
189

1910

@@ -24,31 +15,16 @@ class ScalingConfigManualDict(TypedDict, total=False):
2415
replicas: int
2516

2617

27-
if NotRequired is not None:
28-
# Python 3.11+ or typing_extensions available - use NotRequired for better type hints
29-
class ReadCapacityDedicatedConfigDict(TypedDict):
30-
"""TypedDict for dedicated read capacity configuration.
18+
class ReadCapacityDedicatedConfigDict(TypedDict):
19+
"""TypedDict for dedicated read capacity configuration.
3120
32-
Required fields: node_type, scaling
33-
Optional fields: manual
34-
"""
21+
Required fields: node_type, scaling
22+
Optional fields: manual
23+
"""
3524

36-
node_type: str # Required: "t1" or "b1"
37-
scaling: str # Required: "Manual" or other scaling types
38-
manual: NotRequired[ScalingConfigManualDict] # Optional
39-
else:
40-
# Fallback for older Python versions - all fields optional
41-
class ReadCapacityDedicatedConfigDict(TypedDict, total=False): # type: ignore[no-redef]
42-
"""TypedDict for dedicated read capacity configuration.
43-
44-
Note: In older Python versions without NotRequired support, all fields
45-
are marked as optional. However, node_type and scaling are required
46-
when using Dedicated mode. Users must provide these fields.
47-
"""
48-
49-
node_type: str # Required: "t1" or "b1"
50-
scaling: str # Required: "Manual" or other scaling types
51-
manual: ScalingConfigManualDict # Optional
25+
node_type: str # Required: "t1" or "b1"
26+
scaling: str # Required: "Manual" or other scaling types
27+
manual: NotRequired[ScalingConfigManualDict] # Optional
5228

5329

5430
class ReadCapacityOnDemandDict(TypedDict):

0 commit comments

Comments
 (0)