@@ -274,6 +274,47 @@ def test__TypeHint__from_newtype() -> None:
274
274
assert hint .hint is MyInt
275
275
276
276
277
+ def test__TypeHint__from_generic_with_unbound_typevar () -> None :
278
+ """
279
+ Inheriting from a generic base class without parameterizing it is not valid and databind cannot handle the
280
+ case correctly. The `TypeHint.bases` will appear as the bases' bases (that is because `__orig_bases__` is not
281
+ set on the new subclass and instead it reads the attribute from the parent).
282
+ """
283
+
284
+ T = TypeVar ("T" )
285
+ U = TypeVar ("U" )
286
+
287
+ class Base (Generic [T ]):
288
+ a : int
289
+
290
+ class Incorrect (Base ): # type: ignore[type-arg]
291
+ b : str
292
+
293
+ class Correct (Base [U ]):
294
+ b : str
295
+
296
+ hint = TypeHint (Base )
297
+ assert isinstance (hint , ClassTypeHint )
298
+ assert hint .type == Base
299
+ assert hint .bases == (Generic [T ],)
300
+ assert hint .origin is None
301
+ assert "__orig_bases__" in vars (Base )
302
+
303
+ hint = TypeHint (Incorrect )
304
+ assert isinstance (hint , ClassTypeHint )
305
+ assert hint .type == Incorrect
306
+ assert hint .bases == (Generic [T ],) # Note how this is not (Base,)
307
+ assert hint .origin is None
308
+ assert "__orig_bases__" not in vars (Incorrect )
309
+
310
+ hint = TypeHint (Correct )
311
+ assert isinstance (hint , ClassTypeHint )
312
+ assert hint .type == Correct
313
+ assert hint .bases == (Base [U ],) # type: ignore[valid-type]
314
+ assert hint .origin is None
315
+ assert "__orig_bases__" in vars (Correct )
316
+
317
+
277
318
def test__ClassTypeHint__parametrize () -> None :
278
319
"""This method tests the infusion of type parameters into other types.
279
320
0 commit comments