@@ -494,6 +494,19 @@ pub enum MarkerExpression {
494
494
} ,
495
495
}
496
496
497
+ /// The kind of a [`MarkerExpression`].
498
+ #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
499
+ pub ( crate ) enum MarkerExpressionKind {
500
+ /// A version expression, e.g. `<version key> <version op> <quoted PEP 440 version>`.
501
+ Version ( MarkerValueVersion ) ,
502
+ /// A version "in" expression, e.g. `<version key> in <quoted list of PEP 440 versions>`.
503
+ VersionIn ( MarkerValueVersion ) ,
504
+ /// A string marker comparison, e.g. `sys_platform == '...'`.
505
+ String ( MarkerValueString ) ,
506
+ /// An extra expression, e.g. `extra == '...'`.
507
+ Extra ,
508
+ }
509
+
497
510
/// The operator for an extra expression, either '==' or '!='.
498
511
#[ derive( Clone , Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
499
512
pub enum ExtraOperator {
@@ -564,6 +577,16 @@ impl MarkerExpression {
564
577
pub fn from_str ( s : & str ) -> Result < Option < Self > , Pep508Error > {
565
578
MarkerExpression :: parse_reporter ( s, & mut TracingReporter )
566
579
}
580
+
581
+ /// Return the kind of this marker expression.
582
+ pub ( crate ) fn kind ( & self ) -> MarkerExpressionKind {
583
+ match self {
584
+ MarkerExpression :: Version { key, .. } => MarkerExpressionKind :: Version ( * key) ,
585
+ MarkerExpression :: VersionIn { key, .. } => MarkerExpressionKind :: VersionIn ( * key) ,
586
+ MarkerExpression :: String { key, .. } => MarkerExpressionKind :: String ( * key) ,
587
+ MarkerExpression :: Extra { .. } => MarkerExpressionKind :: Extra ,
588
+ }
589
+ }
567
590
}
568
591
569
592
impl Display for MarkerExpression {
@@ -692,13 +715,11 @@ impl MarkerTree {
692
715
}
693
716
694
717
/// Combine this marker tree with the one given via a conjunction.
695
- #[ allow( clippy:: needless_pass_by_value) ]
696
718
pub fn and ( & mut self , tree : MarkerTree ) {
697
719
self . 0 = INTERNER . lock ( ) . and ( self . 0 , tree. 0 ) ;
698
720
}
699
721
700
722
/// Combine this marker tree with the one given via a disjunction.
701
- #[ allow( clippy:: needless_pass_by_value) ]
702
723
pub fn or ( & mut self , tree : MarkerTree ) {
703
724
self . 0 = INTERNER . lock ( ) . or ( self . 0 , tree. 0 ) ;
704
725
}
@@ -708,7 +729,6 @@ impl MarkerTree {
708
729
///
709
730
/// If the marker set is always `true`, then it can be said that `self`
710
731
/// implies `consequent`.
711
- #[ allow( clippy:: needless_pass_by_value) ]
712
732
pub fn implies ( & mut self , consequent : MarkerTree ) {
713
733
// This could probably be optimized, but is clearly
714
734
// correct, since logical implication is `-P or Q`.
@@ -723,10 +743,8 @@ impl MarkerTree {
723
743
/// never both evaluate to `true` in a given environment. However, this method may return
724
744
/// false negatives, i.e. it may not be able to detect that two markers are disjoint for
725
745
/// complex expressions.
726
- pub fn is_disjoint ( & self , other : MarkerTree ) -> bool {
727
- let mutex = & * MUTUAL_EXCLUSIONS ;
728
- let node = INTERNER . lock ( ) . and ( self . 0 , other. 0 ) ;
729
- node. is_false ( ) || INTERNER . lock ( ) . is_disjoint ( node, mutex. 0 )
746
+ pub fn is_disjoint ( self , other : MarkerTree ) -> bool {
747
+ INTERNER . lock ( ) . is_disjoint ( self . 0 , other. 0 )
730
748
}
731
749
732
750
/// Returns the contents of this marker tree, if it contains at least one expression.
@@ -1019,7 +1037,6 @@ impl MarkerTree {
1019
1037
/// results of that simplification. (If `requires-python` changes, then one
1020
1038
/// should reconstitute all relevant markers from the source data.)
1021
1039
#[ must_use]
1022
- #[ allow( clippy:: needless_pass_by_value) ]
1023
1040
pub fn simplify_python_versions (
1024
1041
self ,
1025
1042
lower : Bound < & Version > ,
@@ -1040,7 +1057,6 @@ impl MarkerTree {
1040
1057
/// `python_full_version <= '3.10'`, this would result in a marker of
1041
1058
/// `python_full_version >= '3.8' and python_full_version <= '3.10'`.
1042
1059
#[ must_use]
1043
- #[ allow( clippy:: needless_pass_by_value) ]
1044
1060
pub fn complexify_python_versions (
1045
1061
self ,
1046
1062
lower : Bound < & Version > ,
@@ -2247,7 +2263,7 @@ mod test {
2247
2263
2248
2264
assert_simplifies (
2249
2265
"((extra == 'a' or extra == 'b') and extra == 'c') or extra == 'b'" ,
2250
- "( extra == 'a' and extra == 'c') or extra == 'b' " ,
2266
+ "extra == 'b' or ( extra == 'a' and extra == 'c') " ,
2251
2267
) ;
2252
2268
2253
2269
// post-normalization filtering
@@ -2469,10 +2485,10 @@ mod test {
2469
2485
or (implementation_name != 'pypy' and sys_platform == 'win32')
2470
2486
or (sys_platform == 'win32' and os_name != 'nt')
2471
2487
or (sys_platform != 'win32' and os_name == 'nt')" ,
2472
- "(sys_platform != 'win32' and implementation_name == 'pypy') \
2488
+ "(implementation_name == 'pypy' and sys_platform != 'win32') \
2489
+ or (implementation_name != 'pypy' and sys_platform == 'win32') \
2473
2490
or (os_name != 'nt' and sys_platform == 'win32') \
2474
- or (os_name == 'nt' and sys_platform != 'win32') \
2475
- or (sys_platform == 'win32' and implementation_name != 'pypy')",
2491
+ or (os_name == 'nt' and sys_platform != 'win32')",
2476
2492
) ;
2477
2493
2478
2494
// This is a case we can simplify fully, but it's dependent on the variable order.
@@ -2500,7 +2516,7 @@ mod test {
2500
2516
"(os_name == 'Linux' and sys_platform == 'win32') \
2501
2517
or (os_name != 'Linux' and sys_platform == 'win32' and python_version == '3.7') \
2502
2518
or (os_name != 'Linux' and sys_platform == 'win32' and python_version == '3.8')",
2503
- "(sys_platform == 'win32' and python_full_version >= '3.7' and python_full_version < '3.9') or (os_name == 'Linux' and sys_platform == 'win32')" ,
2519
+ "(python_full_version >= '3.7' and python_full_version < '3.9' and sys_platform == 'win32 ') or (os_name == 'Linux' and sys_platform == 'win32')" ,
2504
2520
) ;
2505
2521
2506
2522
assert_simplifies (
@@ -2522,9 +2538,9 @@ mod test {
2522
2538
assert_simplifies (
2523
2539
"(os_name == 'nt' and sys_platform == 'win32') \
2524
2540
or (os_name != 'nt' and platform_version == '1' and (sys_platform == 'win32' or sys_platform == 'win64'))",
2525
- "(sys_platform == 'win32 ' and platform_version == '1') \
2526
- or (os_name != 'nt' and sys_platform == 'win64' and platform_version == '1 ') \
2527
- or (os_name == 'nt ' and sys_platform == 'win32')",
2541
+ "(os_name != 'nt ' and platform_version == '1' and sys_platform == 'win64 ') \
2542
+ or (os_name == 'nt' and sys_platform == 'win32 ') \
2543
+ or (platform_version == '1 ' and sys_platform == 'win32')",
2528
2544
) ;
2529
2545
2530
2546
assert_simplifies (
0 commit comments