-
-
Notifications
You must be signed in to change notification settings - Fork 117
Fix tests on Python 3.12 #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d96be43
Fix tests on Python 3.12
JelleZijlstra f3ba193
More tests
JelleZijlstra 99d7c8c
don't need that
JelleZijlstra c4ee8c7
if only we had Black
JelleZijlstra bca6f65
Merge branch 'main' into 312
JelleZijlstra da4a52e
import textwrap
JelleZijlstra abe9377
Update src/test_typing_extensions.py
JelleZijlstra 665e2b7
Fix previous alphas
JelleZijlstra 9153e12
Merge branch 'main' into 312
JelleZijlstra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -758,6 +758,7 @@ def runtime_checkable(cls): | |
SupportsInt = typing.SupportsInt | ||
SupportsFloat = typing.SupportsFloat | ||
SupportsComplex = typing.SupportsComplex | ||
SupportsBytes = typing.SupportsBytes | ||
SupportsIndex = typing.SupportsIndex | ||
SupportsAbs = typing.SupportsAbs | ||
SupportsRound = typing.SupportsRound | ||
|
@@ -1342,39 +1343,53 @@ def __repr__(self): | |
above.""") | ||
|
||
|
||
def _set_default(type_param, default): | ||
if isinstance(default, (tuple, list)): | ||
type_param.__default__ = tuple((typing._type_check(d, "Default must be a type") | ||
for d in default)) | ||
elif default != _marker: | ||
type_param.__default__ = typing._type_check(default, "Default must be a type") | ||
else: | ||
type_param.__default__ = None | ||
|
||
|
||
class _DefaultMixin: | ||
"""Mixin for TypeVarLike defaults.""" | ||
|
||
__slots__ = () | ||
|
||
def __init__(self, default): | ||
if isinstance(default, (tuple, list)): | ||
self.__default__ = tuple((typing._type_check(d, "Default must be a type") | ||
for d in default)) | ||
elif default != _marker: | ||
self.__default__ = typing._type_check(default, "Default must be a type") | ||
else: | ||
self.__default__ = None | ||
__init__ = _set_default | ||
|
||
|
||
# Add default and infer_variance parameters from PEP 696 and 695 | ||
class TypeVar(typing.TypeVar, _DefaultMixin, _root=True): | ||
"""Type variable.""" | ||
|
||
__module__ = 'typing' | ||
|
||
def __init__(self, name, *constraints, bound=None, | ||
class _TypeVarMeta(type): | ||
def __call__(self, name, *constraints, bound=None, | ||
covariant=False, contravariant=False, | ||
default=_marker, infer_variance=False): | ||
super().__init__(name, *constraints, bound=bound, covariant=covariant, | ||
contravariant=contravariant) | ||
_DefaultMixin.__init__(self, default) | ||
self.__infer_variance__ = infer_variance | ||
if hasattr(typing, "TypeAliasType"): | ||
# PEP 695 implemented, can pass infer_variance to typing.TypeVar | ||
typevar = typing.TypeVar(name, *constraints, bound=bound, | ||
covariant=covariant, contravariant=contravariant, | ||
infer_variance=infer_variance) | ||
else: | ||
typevar = typing.TypeVar(name, *constraints, bound=bound, | ||
covariant=covariant, contravariant=contravariant) | ||
typevar.__infer_variance__ = infer_variance | ||
_set_default(typevar, default) | ||
|
||
# for pickling: | ||
def_mod = _caller() | ||
if def_mod != 'typing_extensions': | ||
self.__module__ = def_mod | ||
typevar.__module__ = def_mod | ||
return typevar | ||
|
||
def __instancecheck__(self, __instance: Any) -> bool: | ||
return isinstance(__instance, typing.TypeVar) | ||
|
||
|
||
class TypeVar(metaclass=_TypeVarMeta): | ||
"""Type variable.""" | ||
|
||
__module__ = 'typing' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. heh |
||
|
||
|
||
# Python 3.10+ has PEP 612 | ||
|
@@ -1442,22 +1457,28 @@ def __eq__(self, other): | |
# 3.10+ | ||
if hasattr(typing, 'ParamSpec'): | ||
|
||
# Add default Parameter - PEP 696 | ||
class ParamSpec(typing.ParamSpec, _DefaultMixin, _root=True): | ||
"""Parameter specification variable.""" | ||
|
||
__module__ = 'typing' | ||
|
||
def __init__(self, name, *, bound=None, covariant=False, contravariant=False, | ||
# Add default parameter - PEP 696 | ||
class _ParamSpecMeta(type): | ||
def __call__(self, name, *, bound=None, | ||
covariant=False, contravariant=False, | ||
default=_marker): | ||
super().__init__(name, bound=bound, covariant=covariant, | ||
contravariant=contravariant) | ||
_DefaultMixin.__init__(self, default) | ||
paramspec = typing.ParamSpec(name, bound=bound, | ||
covariant=covariant, contravariant=contravariant) | ||
_set_default(paramspec, default) | ||
|
||
# for pickling: | ||
def_mod = _caller() | ||
if def_mod != 'typing_extensions': | ||
self.__module__ = def_mod | ||
paramspec.__module__ = def_mod | ||
return paramspec | ||
|
||
def __instancecheck__(self, __instance: Any) -> bool: | ||
return isinstance(__instance, typing.ParamSpec) | ||
|
||
class ParamSpec(metaclass=_ParamSpecMeta): | ||
"""Parameter specification.""" | ||
|
||
__module__ = 'typing' | ||
|
||
# 3.7-3.9 | ||
else: | ||
|
@@ -2060,18 +2081,28 @@ def _is_unpack(obj): | |
|
||
if hasattr(typing, "TypeVarTuple"): # 3.11+ | ||
|
||
# Add default Parameter - PEP 696 | ||
class TypeVarTuple(typing.TypeVarTuple, _DefaultMixin, _root=True): | ||
"""Type variable tuple.""" | ||
|
||
def __init__(self, name, *, default=_marker): | ||
super().__init__(name) | ||
_DefaultMixin.__init__(self, default) | ||
# Add default parameter - PEP 696 | ||
class _TypeVarTupleMeta(type): | ||
def __call__(self, name, *, default=_marker): | ||
tvt = typing.TypeVarTuple(name) | ||
_set_default(tvt, default) | ||
|
||
# for pickling: | ||
def_mod = _caller() | ||
if def_mod != 'typing_extensions': | ||
self.__module__ = def_mod | ||
tvt.__module__ = def_mod | ||
return tvt | ||
|
||
def __instancecheck__(self, __instance: Any) -> bool: | ||
return isinstance(__instance, typing.TypeVarTuple) | ||
|
||
class TypeVarTuple(metaclass=_TypeVarTupleMeta): | ||
"""Type variable tuple.""" | ||
|
||
__module__ = 'typing' | ||
|
||
def __init_subclass__(self, *args, **kwds): | ||
raise TypeError("Cannot subclass special typing classes") | ||
|
||
else: | ||
class TypeVarTuple(_DefaultMixin): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.