Skip to content

Commit a9aec6d

Browse files
committed
Fix SearchScope dataclass by using slots=True parameter instead of __slots__
The combination of @DataClass(frozen=True), __slots__, and default values causes a ValueError because default values create class variables that conflict with __slots__. Using slots=True parameter in the dataclass decorator handles this correctly in Python 3.10+.
1 parent 56ca5be commit a9aec6d

2 files changed

Lines changed: 13 additions & 32 deletions

File tree

pipenv/patched/pip/_internal/models/search_scope.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import posixpath
55
import urllib.parse
6-
from dataclasses import dataclass, field
6+
from dataclasses import dataclass
77

88
from pipenv.patched.pip._vendor.packaging.utils import canonicalize_name
99

@@ -14,25 +14,17 @@
1414
logger = logging.getLogger(__name__)
1515

1616

17-
@dataclass(frozen=True)
17+
@dataclass(frozen=True, slots=True)
1818
class SearchScope:
1919
"""
2020
Encapsulates the locations that pip is configured to search.
2121
"""
2222

23-
__slots__ = [
24-
"find_links",
25-
"index_urls",
26-
"no_index",
27-
"index_lookup",
28-
"index_restricted",
29-
]
30-
3123
find_links: list[str]
3224
index_urls: list[str]
3325
no_index: bool
34-
index_lookup: dict[str, list[str]] | None = field(default=None)
35-
index_restricted: bool = field(default=False)
26+
index_lookup: dict[str, list[str]] | None = None
27+
index_restricted: bool = False
3628

3729
@classmethod
3830
def create(

tasks/vendoring/patches/patched/pip_index_safety.patch

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,23 @@ diff --git a/pipenv/patched/pip/_internal/models/search_scope.py b/pipenv/patche
3939
index 136163ca0..a41193a6e 100644
4040
--- a/pipenv/patched/pip/_internal/models/search_scope.py
4141
+++ b/pipenv/patched/pip/_internal/models/search_scope.py
42-
@@ -1,6 +1,6 @@
43-
import itertools
44-
import logging
45-
import os
46-
import posixpath
47-
import urllib.parse
48-
-from dataclasses import dataclass
49-
+from dataclasses import dataclass, field
42+
@@ -17,14 +17,13 @@ logger = logging.getLogger(__name__)
5043

51-
from pip._vendor.packaging.utils import canonicalize_name
52-
@@ -20,11 +20,19 @@ class SearchScope:
44+
45+
-@dataclass(frozen=True)
46+
+@dataclass(frozen=True, slots=True)
47+
class SearchScope:
48+
"""
5349
Encapsulates the locations that pip is configured to search.
5450
"""
5551

5652
- __slots__ = ["find_links", "index_urls", "no_index"]
57-
+ __slots__ = [
58-
+ "find_links",
59-
+ "index_urls",
60-
+ "no_index",
61-
+ "index_lookup",
62-
+ "index_restricted",
63-
+ ]
64-
53+
-
6554
find_links: list[str]
6655
index_urls: list[str]
6756
no_index: bool
68-
+ index_lookup: dict[str, list[str]] | None = field(default=None)
69-
+ index_restricted: bool = field(default=False)
57+
+ index_lookup: dict[str, list[str]] | None = None
58+
+ index_restricted: bool = False
7059

7160
@classmethod
7261
def create(

0 commit comments

Comments
 (0)