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

Failure of can_validate on non-generic _SpecialGenericAlias objects. #5

Closed
sg495 opened this issue Jan 6, 2024 · 0 comments
Closed
Labels
bug Something isn't working

Comments

@sg495
Copy link
Contributor

sg495 commented Jan 6, 2024

The can_validate function fails when called on _SpecialGenericAlias objects without a generic type specified.

>>> from typing_validation import can_validate
>>> from typing import Iterable
>>> can_validate(Iterable)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Stefa\Documents\git\hashberg-io\typing-validation\typing_validation\validation.py", line 269, in __repr__
    return header+"\n"+"\n".join(self._repr()[0])
                                 ^^^^^^^^^^^^
  File "C:\Users\Stefa\Documents\git\hashberg-io\typing-validation\typing_validation\validation.py", line 311, in _repr
    pending_type, tag, param = param
    ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '_SpecialGenericAlias' object is not iterable

The issue is in the _recorded_type and _repr methods of TypeInspector:

class TypeInspector:
    def _recorded_type(self, idx: int) -> typing.Tuple[Any, int]:
        # ...omitted...
        if tag == "type":
            if isinstance(param, type):
                return param, idx
        # ...omitted...
    def _repr(self, idx: int = 0, level: int = 0) -> typing.Tuple[typing.List[str], int]:
        # ...omitted...
        if tag == "type":
            if isinstance(param, type):
                return param, idx
        # ...omitted...

The condition isinstance(param, type) should be replaced with not isinstance(param, tuple).

@sg495 sg495 added the bug Something isn't working label Jan 6, 2024
@sg495 sg495 closed this as completed in ca3fb91 Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant