@@ -240,44 +240,53 @@ def create_nested_marker(
240
240
marker = f'{ name } == "{ constraint .text } "'
241
241
else :
242
242
assert isinstance (constraint , VersionRange )
243
+ min_name = max_name = name
244
+
245
+ parts = []
246
+
247
+ # `python_version` is a special case: to keep the constructed marker equivalent
248
+ # to the constraint we need to be careful with the precision.
249
+ #
250
+ # PEP 440 tells us that that when we come to make the comparison the release
251
+ # segment will be zero padded: eg "<= 3.10" is equivalent to "<= 3.10.0".
252
+ #
253
+ # But "python_version <= 3.10" is _not_ equivalent to "python_version <= 3.10.0" -
254
+ # see normalize_python_version_markers.
255
+ #
256
+ # A similar issue arises for a constraint like "> 3.6".
243
257
if constraint .min is not None :
244
- op = ">="
245
- if not constraint .include_min :
246
- op = ">"
247
-
258
+ op = ">=" if constraint .include_min else ">"
248
259
version = constraint .min
249
- if constraint .max is not None :
250
- min_name = max_name = name
251
- if min_name == "python_version" and constraint .min .precision >= 3 :
252
- min_name = "python_full_version"
253
-
254
- if max_name == "python_version" and constraint .max .precision >= 3 :
255
- max_name = "python_full_version"
256
-
257
- text = f'{ min_name } { op } "{ version } "'
258
-
259
- op = "<="
260
- if not constraint .include_max :
261
- op = "<"
260
+ if min_name == "python_version" and version .precision >= 3 :
261
+ min_name = "python_full_version"
262
262
263
- version = constraint .max
263
+ if min_name == "python_version" and not constraint .include_min :
264
+ padding = (
265
+ ".0" * (3 - version .precision ) if version .precision < 3 else ""
266
+ )
267
+ part = f'python_full_version > "{ version } { padding } "'
268
+ else :
269
+ part = f'{ min_name } { op } "{ version } "'
264
270
265
- text += f' and { max_name } { op } "{ version } "'
266
-
267
- return text
268
- elif constraint .max is not None :
269
- op = "<="
270
- if not constraint .include_max :
271
- op = "<"
271
+ parts .append (part )
272
272
273
+ if constraint .max is not None :
274
+ op = "<=" if constraint .include_max else "<"
273
275
version = constraint .max
274
- else :
275
- return " "
276
+ if max_name == "python_version" and version . precision >= 3 :
277
+ max_name = "python_full_version "
276
278
277
- if name == "python_version" and version .precision >= 3 :
278
- name = "python_full_version"
279
+ if name == "python_version" and constraint .include_max :
280
+ padding = (
281
+ ".0" * (3 - version .precision ) if version .precision < 3 else ""
282
+ )
283
+ part = f'python_full_version <= "{ version } { padding } "'
284
+ else :
285
+ part = f'{ max_name } { op } "{ version } "'
286
+
287
+ parts .append (part )
279
288
280
- marker = f' { name } { op } " { version } "'
289
+ marker = " and " . join ( parts )
281
290
282
291
return marker
283
292
0 commit comments