1
+ from __future__ import annotations
2
+
1
3
import logging
2
4
3
5
from pathlib import Path
6
8
from typing import Dict
7
9
from typing import List
8
10
from typing import Mapping
9
- from typing import Optional
10
11
from typing import Union
11
12
from warnings import warn
12
13
@@ -37,8 +38,8 @@ class Factory:
37
38
"""
38
39
39
40
def create_poetry (
40
- self , cwd : Optional [ Path ] = None , with_groups : bool = True
41
- ) -> " Poetry" :
41
+ self , cwd : Path | None = None , with_groups : bool = True
42
+ ) -> Poetry :
42
43
from poetry .core .poetry import Poetry
43
44
from poetry .core .pyproject .toml import PyProjectTOML
44
45
@@ -65,17 +66,17 @@ def create_poetry(
65
66
return Poetry (poetry_file , local_config , package )
66
67
67
68
@classmethod
68
- def get_package (cls , name : str , version : str ) -> " ProjectPackage" :
69
+ def get_package (cls , name : str , version : str ) -> ProjectPackage :
69
70
from poetry .core .packages .project_package import ProjectPackage
70
71
71
72
return ProjectPackage (name , version , version )
72
73
73
74
@classmethod
74
75
def _add_package_group_dependencies (
75
76
cls ,
76
- package : " ProjectPackage" ,
77
- group : Union [ str , " DependencyGroup" ] ,
78
- dependencies : " DependencyConfig" ,
77
+ package : ProjectPackage ,
78
+ group : str | DependencyGroup ,
79
+ dependencies : DependencyConfig ,
79
80
) -> None :
80
81
if isinstance (group , str ):
81
82
if package .has_dependency_group (group ):
@@ -109,11 +110,11 @@ def _add_package_group_dependencies(
109
110
@classmethod
110
111
def configure_package (
111
112
cls ,
112
- package : " ProjectPackage" ,
113
- config : Dict [str , Any ],
113
+ package : ProjectPackage ,
114
+ config : dict [str , Any ],
114
115
root : Path ,
115
116
with_groups : bool = True ,
116
- ) -> " ProjectPackage" :
117
+ ) -> ProjectPackage :
117
118
from poetry .core .packages .dependency import Dependency
118
119
from poetry .core .packages .dependency_group import DependencyGroup
119
120
from poetry .core .spdx .helpers import license_by_id
@@ -131,7 +132,7 @@ def configure_package(
131
132
package .repository_url = config .get ("repository" )
132
133
package .documentation_url = config .get ("documentation" )
133
134
try :
134
- license_ : Optional [ " License" ] = license_by_id (config .get ("license" , "" ))
135
+ license_ : License | None = license_by_id (config .get ("license" , "" ))
135
136
except ValueError :
136
137
license_ = None
137
138
@@ -220,10 +221,10 @@ def configure_package(
220
221
def create_dependency (
221
222
cls ,
222
223
name : str ,
223
- constraint : " DependencyConstraint" ,
224
- groups : Optional [ List [ str ]] = None ,
225
- root_dir : Optional [ Path ] = None ,
226
- ) -> " DependencyTypes" :
224
+ constraint : DependencyConstraint ,
225
+ groups : list [ str ] | None = None ,
226
+ root_dir : Path | None = None ,
227
+ ) -> DependencyTypes :
227
228
from poetry .core .packages .constraints import (
228
229
parse_constraint as parse_generic_constraint ,
229
230
)
@@ -335,7 +336,7 @@ def create_dependency(
335
336
)
336
337
337
338
if not markers :
338
- marker : " BaseMarker" = AnyMarker ()
339
+ marker : BaseMarker = AnyMarker ()
339
340
if python_versions :
340
341
marker = marker .intersect (
341
342
parse_marker (
@@ -367,14 +368,14 @@ def create_dependency(
367
368
368
369
@classmethod
369
370
def validate (
370
- cls , config : Dict [str , Any ], strict : bool = False
371
- ) -> Dict [str , List [str ]]:
371
+ cls , config : dict [str , Any ], strict : bool = False
372
+ ) -> dict [str , list [str ]]:
372
373
"""
373
374
Checks the validity of a configuration
374
375
"""
375
376
from poetry .core .json import validate_object
376
377
377
- result : Dict [str , List [str ]] = {"errors" : [], "warnings" : []}
378
+ result : dict [str , list [str ]] = {"errors" : [], "warnings" : []}
378
379
# Schema validation errors
379
380
validation_errors = validate_object (config , "poetry-schema" )
380
381
@@ -428,7 +429,7 @@ def validate(
428
429
return result
429
430
430
431
@classmethod
431
- def locate (cls , cwd : Optional [ Path ] = None ) -> Path :
432
+ def locate (cls , cwd : Path | None = None ) -> Path :
432
433
cwd = Path (cwd or Path .cwd ())
433
434
candidates = [cwd ]
434
435
candidates .extend (cwd .parents )
0 commit comments