Skip to content

TypeError "Neither typeguard not pytypes is installed"... but typeguard is installed #91

Closed

Description

@smarie

We sometimes encounter this error on minimalistic environments:

Traceback (most recent call last):
  File "C:\<env_path>\lib\site-packages\pyfields\typing_utils.py", line 165, in assert_is_of_type
    is_ok = isinstance(value, types)
  File "C:\Python39\lib\typing.py", line 720, in __instancecheck__
    return self.__subclasscheck__(type(obj))
  File "C:\Python39\lib\typing.py", line 723, in __subclasscheck__
    raise TypeError("Subscripted generics cannot be used with"
TypeError: Subscripted generics cannot be used with class and instance checks

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\<env_path>\lib\site-packages\dq4ts\description.py", line 128, in from_dict
    fields[f.name] = dict_to_pyfields(field_dct, f.type_hint)
  File "C:\<env_path>\lib\site-packages\dq4ts\utils_pyfields.py", line 74, in dict_to_pyfields
    return create_pyfields_instance(cls, init_kwargs)
  File "C:\<env_path>\lib\site-packages\dq4ts\utils_pyfields.py", line 92, in create_pyfields_instance
    return cls(**init_kwargs)
  File "<makefun-gen-15>", line 2, in __init__
  File "C:\<env_path>\lib\site-packages\pyfields\init_makers.py", line 409, in init_fun
    setattr(self, field_name, field_value)
  File "C:\<env_path>\lib\site-packages\pyfields\core.py", line 1127, in __set__
    assert_is_of_type(self, value, t)
  File "C:\<env_path>\lib\site-packages\pyfields\typing_utils.py", line 168, in assert_is_of_type
    raise TypeError("Neither typeguard not pytypes is installed - therefore it is not possible to "
TypeError: not all arguments converted during string formatting

Even if typeguard is installed.

This error is actually due to the absence of packaging module. The fix is therefore to do

> pip install packaging

We should add it to the requirements of this package so that this is automatic in the future.

Activity

  1. smarie commented on Nov 6, 2023

    @smarie
    OwnerAuthor

    The culprit is this line : https://github.com/smarie/python-pyfields/blob/main/pyfields/typing_utils.py#L51
    The import statement should move outside of the try except loop !

  2. added a commit that references this issue on Nov 6, 2023
    aaaae21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions