atom icon indicating copy to clipboard operation
atom copied to clipboard

Fix handling of TypeVar with an object bound

Open MatthieuDartiailh opened this issue 3 years ago • 1 comments

Because this result in having object in types we use a Value member but the parameters are not empty causing an error when instantiating the member. We should at least reset the parameters in such a case.

MatthieuDartiailh avatar Jul 05 '22 19:07 MatthieuDartiailh

Example:

from typing import TypeVar

from atom.api import Atom


T = TypeVar("T")


class A(Atom):

    a: T

Error:

Traceback (most recent call last):
  File "C:\Users\matthieu.dartiailh\Documents\Coding\BugsRepro\atom\unbound_typevar.py", line 10, in <module>
    class A(Atom):
  File "c:\users\matthieu.dartiailh\documents\coding\projects\atom\atom\atom.py", line 283, in __new__
    generate_members_from_cls_namespace(name, dct, type_containers)
  File "c:\users\matthieu.dartiailh\documents\coding\projects\atom\atom\annotation_utils.py", line 136, in generate_members_from_cls_namespace
    namespace[name] = generate_member_from_type_or_generic(
  File "c:\users\matthieu.dartiailh\documents\coding\projects\atom\atom\annotation_utils.py", line 102, in generate_member_from_type_or_generic
    return m_cls(*parameters, **m_kwargs)
  File "c:\users\matthieu.dartiailh\documents\coding\projects\atom\atom\instance.py", line 85, in __init__

    self.set_validate_mode(Validate.Instance, kind)
TypeError: Expected type or tuple of types. Got a tuple containing an instance of `TypeVar` instead.

MatthieuDartiailh avatar Sep 22 '22 15:09 MatthieuDartiailh

Closed by #194 and #207

MatthieuDartiailh avatar Mar 18 '24 17:03 MatthieuDartiailh