File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
src/hypothesis/strategies/_internal Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change
1
+ RELEASE_TYPE: patch
2
+
3
+ This patch fixes :func: `~hypothesis.strategies.from_type ` and
4
+ :func: `~hypothesis.strategies.register_type_strategy ` for
5
+ :obj: `python:typing.NewType ` on Python 3.10, which changed the
6
+ underlying implementation (see :bpo: `44353 ` for details).
Original file line number Diff line number Diff line change @@ -98,13 +98,17 @@ def try_issubclass(thing, superclass):
98
98
99
99
100
100
def is_a_new_type (thing ):
101
- # At runtime, `typing.NewType` returns an identity function rather
102
- # than an actual type, but we can check whether that thing matches.
103
- return (
104
- hasattr (thing , "__supertype__" )
105
- and getattr (thing , "__module__" , None ) in ("typing" , "typing_extensions" )
106
- and inspect .isfunction (thing )
107
- )
101
+ if sys .version_info [:2 ] < (3 , 10 ):
102
+ # At runtime, `typing.NewType` returns an identity function rather
103
+ # than an actual type, but we can check whether that thing matches.
104
+ return (
105
+ hasattr (thing , "__supertype__" )
106
+ and getattr (thing , "__module__" , None ) in ("typing" , "typing_extensions" )
107
+ and inspect .isfunction (thing )
108
+ )
109
+ # In 3.10 and later, NewType is actually a class - which simplifies things.
110
+ # See https://bugs.python.org/issue44353 for links to the various patches.
111
+ return isinstance (thing , typing .NewType ) # pragma: no cover # on 3.8, anyway
108
112
109
113
110
114
def is_a_type (thing ):
You can’t perform that action at this time.
0 commit comments