Skip to content
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

has_fields leads to AttributeError: __mro__ when the argument provided is a typing.Union #86

Open
smarie opened this issue Dec 8, 2022 · 0 comments

Comments

@smarie
Copy link
Owner

smarie commented Dec 8, 2022

from typing import Union
from pyfields import has_fields

has_fields(Union[int, float])

Leads to a non-user-friendly error message:

Traceback (most recent call last):
  ...
  File "<ipython-input-4-0e8bf0e2111b>", line 1, in <module>
    has_fields(Union[int, float])
  File "\site-packages\pyfields\helpers.py", line 146, in has_fields
    return any(yield_fields(cls, include_inherited=include_inherited))
  File "\site-packages\pyfields\helpers.py", line 71, in yield_fields
    where_cls = reversed(getmro(cls)) if ancestors_first else getmro(cls)
  File "C:\Python38\lib\inspect.py", line 489, in getmro
    return cls.__mro__
  File "C:\Python38\lib\typing.py", line 760, in __getattr__
    raise AttributeError(attr)
AttributeError: __mro__

We should rather return None or raise a proper ValueError indicating that cls is not an actual class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant