click-type-test 2.0.1__tar.gz → 2.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: click-type-test
3
- Version: 2.0.1
3
+ Version: 2.0.2
4
4
  Summary: Test that type annotations match click parameter types
5
5
  Author-email: Stephen Rosen <sirosen@globus.org>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: click-type-test
3
- Version: 2.0.1
3
+ Version: 2.0.2
4
4
  Summary: Test that type annotations match click parameter types
5
5
  Author-email: Stephen Rosen <sirosen@globus.org>
6
6
  License: MIT
@@ -552,4 +552,40 @@ def _type_or_literal_is_included(
552
552
  if value in collected_literal_values:
553
553
  return True
554
554
 
555
+ # if the value is a tuple of Literal-viable types, it may match a Literal tuple in
556
+ # a multiple use opt
557
+ if (
558
+ isinstance(value, tuple)
559
+ and any(t.get_origin(x) is tuple for x in possible_types)
560
+ and set(t.get_args(value_type)).issubset({int, str, bool})
561
+ ):
562
+ for tuple_type in possible_types:
563
+ # we're only interested in types of the form tuple[T, ...]
564
+ if t.get_origin(tuple_type) is not tuple:
565
+ continue
566
+ typeargs = t.get_args(tuple_type)
567
+ if len(typeargs) != 2 or typeargs[1] is not Ellipsis:
568
+ continue
569
+
570
+ multi_use_type = typeargs[0]
571
+
572
+ # if it's a literal, check if all of the values are matched
573
+ if t.get_origin(multi_use_type) is t.Literal and all(
574
+ member in t.get_args(multi_use_type) for member in value
575
+ ):
576
+ return True
577
+
578
+ # otherwise, not a literal, check if all of the types used are within the
579
+ # type (potential union)
580
+ member_types = {_type_of_value(member) for member in value}
581
+ if _is_union(multi_use_type):
582
+ union_members = set(t.get_args(multi_use_type))
583
+ if member_types.issubset(union_members):
584
+ return True
585
+ else:
586
+ if len(member_types) == 1 and _compare_types(
587
+ member_types.pop(), multi_use_type
588
+ ):
589
+ return True
590
+
555
591
  return False
@@ -10,7 +10,7 @@ lint = ["pre-commit"]
10
10
 
11
11
  [project]
12
12
  name = "click-type-test"
13
- version = "2.0.1"
13
+ version = "2.0.2"
14
14
  description = "Test that type annotations match click parameter types"
15
15
  readme = "README.md"
16
16
  requires-python = ">=3.10"