@@ -773,6 +773,45 @@ def test_legacy_converters(self):
773
773
module , function = block .signatures
774
774
self .assertIsInstance ((function .parameters ['path' ]).converter , clinic .str_converter )
775
775
776
+ def test_legacy_converters_non_string_constant_annotation (self ):
777
+ expected_failure_message = """\
778
+ Error on line 0:
779
+ Annotations must be either a name, a function call, or a string.
780
+ """
781
+
782
+ s = self .parse_function_should_fail ('module os\n os.access\n path: 42' )
783
+ self .assertEqual (s , expected_failure_message )
784
+
785
+ s = self .parse_function_should_fail ('module os\n os.access\n path: 42.42' )
786
+ self .assertEqual (s , expected_failure_message )
787
+
788
+ s = self .parse_function_should_fail ('module os\n os.access\n path: 42j' )
789
+ self .assertEqual (s , expected_failure_message )
790
+
791
+ s = self .parse_function_should_fail ('module os\n os.access\n path: b"42"' )
792
+ self .assertEqual (s , expected_failure_message )
793
+
794
+ def test_other_bizarre_things_in_annotations_fail (self ):
795
+ expected_failure_message = """\
796
+ Error on line 0:
797
+ Annotations must be either a name, a function call, or a string.
798
+ """
799
+
800
+ s = self .parse_function_should_fail (
801
+ 'module os\n os.access\n path: {"some": "dictionary"}'
802
+ )
803
+ self .assertEqual (s , expected_failure_message )
804
+
805
+ s = self .parse_function_should_fail (
806
+ 'module os\n os.access\n path: ["list", "of", "strings"]'
807
+ )
808
+ self .assertEqual (s , expected_failure_message )
809
+
810
+ s = self .parse_function_should_fail (
811
+ 'module os\n os.access\n path: (x for x in range(42))'
812
+ )
813
+ self .assertEqual (s , expected_failure_message )
814
+
776
815
def parse (self , text ):
777
816
c = FakeClinic ()
778
817
parser = DSLParser (c )
0 commit comments