Skip to content

Commit

Permalink
Fix "accepts only single type" errors (#1130)
Browse files Browse the repository at this point in the history
- Add "a" to make the message grammatical
- Add a trailing period because _type_check adds another sentence after it. For example, `Unpack[3]` on 3.10 currently fails with `TypeError: Unpack accepts only single type Got 3.`.
- Use an f-string
  • Loading branch information
JelleZijlstra committed Apr 11, 2022
1 parent 9169152 commit cba3a90
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions typing_extensions/src/typing_extensions.py
Expand Up @@ -157,7 +157,7 @@ def __repr__(self):

def __getitem__(self, parameters):
item = typing._type_check(parameters,
f'{self._name} accepts only single type')
f'{self._name} accepts only a single type.')
return typing._GenericAlias(self, (item,))

Final = _FinalForm('Final',
Expand Down Expand Up @@ -1336,7 +1336,7 @@ def is_str(val: Union[str, float]):
``TypeGuard`` also works with type variables. For more information, see
PEP 647 (User-Defined Type Guards).
"""
item = typing._type_check(parameters, f'{self} accepts only single type.')
item = typing._type_check(parameters, f'{self} accepts only a single type.')
return typing._GenericAlias(self, (item,))
# 3.7-3.8
else:
Expand Down Expand Up @@ -1539,7 +1539,7 @@ class Movie(TypedDict, total=False):
There is no runtime checking that a required key is actually provided
when instantiating a related TypedDict.
"""
item = typing._type_check(parameters, f'{self._name} accepts only single type')
item = typing._type_check(parameters, f'{self._name} accepts only a single type.')
return typing._GenericAlias(self, (item,))

@_ExtensionsSpecialForm
Expand All @@ -1556,7 +1556,7 @@ class Movie(TypedDict):
year=1999,
)
"""
item = typing._type_check(parameters, f'{self._name} accepts only single type')
item = typing._type_check(parameters, f'{self._name} accepts only a single type.')
return typing._GenericAlias(self, (item,))

else:
Expand All @@ -1566,7 +1566,7 @@ def __repr__(self):

def __getitem__(self, parameters):
item = typing._type_check(parameters,
'{} accepts only single type'.format(self._name))
f'{self._name} accepts only a single type.')
return typing._GenericAlias(self, (item,))

Required = _RequiredForm(
Expand Down Expand Up @@ -1622,7 +1622,7 @@ def add_batch_axis(
) -> Array[Batch, Unpack[Shape]]: ...
"""
item = typing._type_check(parameters, f'{self._name} accepts only single type')
item = typing._type_check(parameters, f'{self._name} accepts only a single type.')
return _UnpackAlias(self, (item,))

def _is_unpack(obj):
Expand All @@ -1638,7 +1638,7 @@ def __repr__(self):

def __getitem__(self, parameters):
item = typing._type_check(parameters,
f'{self._name} accepts only single type')
f'{self._name} accepts only a single type.')
return _UnpackAlias(self, (item,))

Unpack = _UnpackForm(
Expand Down

0 comments on commit cba3a90

Please sign in to comment.