| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -875,7 +875,7 @@ def test_union_parameter_substitution_errors(self): | |||
| 875 | 875 | T = typing.TypeVar("T") | |
| 876 | 876 | x = int | T | |
| 877 | 877 | with self.assertRaises(TypeError): | |
| 878 | - x[42] | ||
| 878 | + x[int, str] | ||
| 879 | 879 | ||
| 880 | 880 | def test_or_type_operator_with_forward(self): | |
| 881 | 881 | T = typing.TypeVar('T') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -345,7 +345,7 @@ def test_cannot_instantiate_vars(self): | |||
| 345 | 345 | ||
| 346 | 346 | def test_bound_errors(self): | |
| 347 | 347 | with self.assertRaises(TypeError): | |
| 348 | - TypeVar('X', bound=42) | ||
| 348 | + TypeVar('X', bound=Union) | ||
| 349 | 349 | with self.assertRaises(TypeError): | |
| 350 | 350 | TypeVar('X', str, float, bound=Employee) | |
| 351 | 351 | ||
@@ -2591,9 +2591,6 @@ def test_extended_generic_rules_eq(self): | |||
| 2591 | 2591 | class Base: ... | |
| 2592 | 2592 | class Derived(Base): ... | |
| 2593 | 2593 | self.assertEqual(Union[T, Base][Union[Base, Derived]], Union[Base, Derived]) | |
| 2594 | - with self.assertRaises(TypeError): | ||
| 2595 | - Union[T, int][1] | ||
| 2596 | - | ||
| 2597 | 2594 | self.assertEqual(Callable[[T], T][KT], Callable[[KT], KT]) | |
| 2598 | 2595 | self.assertEqual(Callable[..., List[T]][int], Callable[..., List[int]]) | |
| 2599 | 2596 | ||
@@ -3136,8 +3133,6 @@ class Foo(obj): | |||
| 3136 | 3133 | class ClassVarTests(BaseTestCase): | |
| 3137 | 3134 | ||
| 3138 | 3135 | def test_basics(self): | |
| 3139 | - with self.assertRaises(TypeError): | ||
| 3140 | - ClassVar[1] | ||
| 3141 | 3136 | with self.assertRaises(TypeError): | |
| 3142 | 3137 | ClassVar[int, str] | |
| 3143 | 3138 | with self.assertRaises(TypeError): | |
@@ -3176,8 +3171,6 @@ class FinalTests(BaseTestCase): | |||
| 3176 | 3171 | ||
| 3177 | 3172 | def test_basics(self): | |
| 3178 | 3173 | Final[int] # OK | |
| 3179 | - with self.assertRaises(TypeError): | ||
| 3180 | - Final[1] | ||
| 3181 | 3174 | with self.assertRaises(TypeError): | |
| 3182 | 3175 | Final[int, str] | |
| 3183 | 3176 | with self.assertRaises(TypeError): | |
@@ -3591,14 +3584,6 @@ def foo(a: 'Node[T'): | |||
| 3591 | 3584 | with self.assertRaises(SyntaxError): | |
| 3592 | 3585 | get_type_hints(foo) | |
| 3593 | 3586 | ||
| 3594 | - def test_type_error(self): | ||
| 3595 | - | ||
| 3596 | - def foo(a: Tuple['42']): | ||
| 3597 | - pass | ||
| 3598 | - | ||
| 3599 | - with self.assertRaises(TypeError): | ||
| 3600 | - get_type_hints(foo) | ||
| 3601 | - | ||
| 3602 | 3587 | def test_name_error(self): | |
| 3603 | 3588 | ||
| 3604 | 3589 | def foo(a: 'Noode[T]'): | |
@@ -5011,8 +4996,6 @@ def test_namedtuple_keyword_usage(self): | |||
| 5011 | 4996 | self.assertEqual(LocalEmployee.__annotations__, dict(name=str, age=int)) | |
| 5012 | 4997 | with self.assertRaises(TypeError): | |
| 5013 | 4998 | NamedTuple('Name', [('x', int)], y=str) | |
| 5014 | - with self.assertRaises(TypeError): | ||
| 5015 | - NamedTuple('Name', x=1, y='a') | ||
| 5016 | 4999 | ||
| 5017 | 5000 | def test_namedtuple_special_keyword_names(self): | |
| 5018 | 5001 | NT = NamedTuple("NT", cls=type, self=object, typename=str, fields=list) | |
@@ -5048,8 +5031,6 @@ def test_namedtuple_errors(self): | |||
| 5048 | 5031 | NamedTuple('Emp', [('_name', str)]) | |
| 5049 | 5032 | with self.assertRaises(TypeError): | |
| 5050 | 5033 | NamedTuple(typename='Emp', name=str, id=int) | |
| 5051 | - with self.assertRaises(TypeError): | ||
| 5052 | - NamedTuple('Emp', fields=[('name', str), ('id', int)]) | ||
| 5053 | 5034 | ||
| 5054 | 5035 | def test_copy_and_pickle(self): | |
| 5055 | 5036 | global Emp # pickle wants to reference the class by name | |
@@ -5124,7 +5105,6 @@ def test_typeddict_create_errors(self): | |||
| 5124 | 5105 | TypedDict() | |
| 5125 | 5106 | with self.assertRaises(TypeError): | |
| 5126 | 5107 | TypedDict('Emp', [('name', str)], None) | |
| 5127 | - | ||
| 5128 | 5108 | with self.assertRaises(TypeError): | |
| 5129 | 5109 | TypedDict(_typename='Emp', name=str, id=int) | |
| 5130 | 5110 | ||
@@ -5138,13 +5118,6 @@ def test_typeddict_errors(self): | |||
| 5138 | 5118 | isinstance(jim, Emp) | |
| 5139 | 5119 | with self.assertRaises(TypeError): | |
| 5140 | 5120 | issubclass(dict, Emp) | |
| 5141 | - # We raise a DeprecationWarning for the keyword syntax | ||
| 5142 | - # before the TypeError. | ||
| 5143 | - with self.assertWarns(DeprecationWarning): | ||
| 5144 | - with self.assertRaises(TypeError): | ||
| 5145 | - TypedDict('Hi', x=1) | ||
| 5146 | - with self.assertRaises(TypeError): | ||
| 5147 | - TypedDict('Hi', [('x', int), ('y', 1)]) | ||
| 5148 | 5121 | with self.assertRaises(TypeError): | |
| 5149 | 5122 | TypedDict('Hi', [('x', int)], y=int) | |
| 5150 | 5123 | ||
@@ -5916,6 +5889,9 @@ def test_basics(self): | |||
| 5916 | 5889 | def foo(arg) -> TypeGuard[int]: ... | |
| 5917 | 5890 | self.assertEqual(gth(foo), {'return': TypeGuard[int]}) | |
| 5918 | 5891 | ||
| 5892 | + with self.assertRaises(TypeError): | ||
| 5893 | + TypeGuard[int, str] | ||
| 5894 | + | ||
| 5919 | 5895 | def test_repr(self): | |
| 5920 | 5896 | self.assertEqual(repr(TypeGuard), 'typing.TypeGuard') | |
| 5921 | 5897 | cv = TypeGuard[int] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -185,10 +185,7 @@ def _type_check(arg, msg, is_argument=True, module=None, *, allow_special_forms= | |||
| 185 | 185 | return arg | |
| 186 | 186 | if isinstance(arg, _SpecialForm) or arg in (Generic, Protocol): | |
| 187 | 187 | raise TypeError(f"Plain {arg} is not valid as type argument") | |
| 188 | - if isinstance(arg, (type, TypeVar, ForwardRef, types.UnionType, ParamSpec, | ||
| 189 | - ParamSpecArgs, ParamSpecKwargs, TypeVarTuple)): | ||
| 190 | - return arg | ||
| 191 | - if not callable(arg): | ||
| 188 | + if type(arg) is tuple: | ||
| 192 | 189 | raise TypeError(f"{msg} Got {arg!r:.100}.") | |
| 193 | 190 | return arg | |
| 194 | 191 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + No longer require valid typeforms to be callable. This allows :data:`typing.Annotated` to wrap :data:`typing.ParamSpecArgs` and :data:`dataclasses.InitVar`. Patch by Gregory Beauregard. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments