1
1
import dataclasses
2
2
import logging
3
3
import re
4
+ import sys
4
5
from dataclasses import dataclass
5
6
from pathlib import Path
6
7
from typing import (
8
+ TYPE_CHECKING ,
7
9
Any ,
8
10
Dict ,
9
11
Iterable ,
20
22
from pip ._vendor .packaging .markers import Marker
21
23
from pip ._vendor .packaging .specifiers import SpecifierSet
22
24
from pip ._vendor .packaging .version import Version
23
- from pip ._vendor .typing_extensions import Self
24
25
25
26
from pip ._internal .models .direct_url import ArchiveInfo , DirInfo , VcsInfo
26
27
from pip ._internal .models .link import Link
27
28
from pip ._internal .req .req_install import InstallRequirement
28
29
from pip ._internal .utils .urls import url_to_path
29
30
31
+ if TYPE_CHECKING :
32
+ if sys .version_info >= (3 , 11 ):
33
+ from typing import Self
34
+ else :
35
+ from pip ._vendor .typing_extensions import Self
36
+
30
37
T = TypeVar ("T" )
31
38
T2 = TypeVar ("T2" )
32
39
33
40
34
41
class FromDictProtocol (Protocol ):
35
42
@classmethod
36
- def from_dict (cls , d : Dict [str , Any ]) -> Self :
43
+ def from_dict (cls , d : Dict [str , Any ]) -> " Self" :
37
44
pass
38
45
39
46
@@ -218,7 +225,7 @@ def __post_init__(self) -> None:
218
225
raise PylockValidationError ("No path nor url set for vcs package" )
219
226
220
227
@classmethod
221
- def from_dict (cls , d : Dict [str , Any ]) -> Self :
228
+ def from_dict (cls , d : Dict [str , Any ]) -> " Self" :
222
229
return cls (
223
230
type = _get_required (d , str , "type" ),
224
231
url = _get (d , str , "url" ),
@@ -236,7 +243,7 @@ class PackageDirectory:
236
243
subdirectory : Optional [str ]
237
244
238
245
@classmethod
239
- def from_dict (cls , d : Dict [str , Any ]) -> Self :
246
+ def from_dict (cls , d : Dict [str , Any ]) -> " Self" :
240
247
return cls (
241
248
path = _get_required (d , str , "path" ),
242
249
editable = _get (d , bool , "editable" ),
@@ -258,7 +265,7 @@ def __post_init__(self) -> None:
258
265
raise PylockValidationError ("No path nor url set for archive package" )
259
266
260
267
@classmethod
261
- def from_dict (cls , d : Dict [str , Any ]) -> Self :
268
+ def from_dict (cls , d : Dict [str , Any ]) -> " Self" :
262
269
return cls (
263
270
url = _get (d , str , "url" ),
264
271
path = _get (d , str , "path" ),
@@ -282,7 +289,7 @@ def __post_init__(self) -> None:
282
289
raise PylockValidationError ("No path nor url set for sdist package" )
283
290
284
291
@classmethod
285
- def from_dict (cls , d : Dict [str , Any ]) -> Self :
292
+ def from_dict (cls , d : Dict [str , Any ]) -> " Self" :
286
293
return cls (
287
294
name = _get_required (d , str , "name" ),
288
295
url = _get (d , str , "url" ),
@@ -306,7 +313,7 @@ def __post_init__(self) -> None:
306
313
raise PylockValidationError ("No path nor url set for wheel package" )
307
314
308
315
@classmethod
309
- def from_dict (cls , d : Dict [str , Any ]) -> Self :
316
+ def from_dict (cls , d : Dict [str , Any ]) -> " Self" :
310
317
wheel = cls (
311
318
name = _get_required (d , str , "name" ),
312
319
url = _get (d , str , "url" ),
@@ -349,7 +356,7 @@ def __post_init__(self) -> None:
349
356
)
350
357
351
358
@classmethod
352
- def from_dict (cls , d : Dict [str , Any ]) -> Self :
359
+ def from_dict (cls , d : Dict [str , Any ]) -> " Self" :
353
360
package = cls (
354
361
name = _get_required (d , str , "name" ),
355
362
version = _get_as (d , str , Version , "version" ),
@@ -364,7 +371,9 @@ def from_dict(cls, d: Dict[str, Any]) -> Self:
364
371
return package
365
372
366
373
@classmethod
367
- def from_install_requirement (cls , ireq : InstallRequirement , base_dir : Path ) -> Self :
374
+ def from_install_requirement (
375
+ cls , ireq : InstallRequirement , base_dir : Path
376
+ ) -> "Self" :
368
377
base_dir = base_dir .resolve ()
369
378
dist = ireq .get_dist ()
370
379
download_info = ireq .download_info
@@ -484,7 +493,7 @@ def to_dict(self) -> Dict[str, Any]:
484
493
return dataclasses .asdict (self , dict_factory = _toml_dict_factory )
485
494
486
495
@classmethod
487
- def from_dict (cls , d : Dict [str , Any ]) -> Self :
496
+ def from_dict (cls , d : Dict [str , Any ]) -> " Self" :
488
497
return cls (
489
498
lock_version = _get_required_as (d , str , Version , "lock-version" ),
490
499
environments = _get_list_as (d , str , Marker , "environments" ),
@@ -496,7 +505,7 @@ def from_dict(cls, d: Dict[str, Any]) -> Self:
496
505
@classmethod
497
506
def from_install_requirements (
498
507
cls , install_requirements : Iterable [InstallRequirement ], base_dir : Path
499
- ) -> Self :
508
+ ) -> " Self" :
500
509
return cls (
501
510
lock_version = Version ("1.0" ),
502
511
environments = None , # not supported
0 commit comments