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

Union without typeguard fails without explicit message #262

Closed
jasle opened this issue May 9, 2024 · 3 comments
Closed

Union without typeguard fails without explicit message #262

jasle opened this issue May 9, 2024 · 3 comments

Comments

@jasle
Copy link
Contributor

jasle commented May 9, 2024

Currently marshmallow_dataclass fails without an explicit error message when trying to use Unions but missing the typeguard dependency.

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../marshmallow_dataclass/lazy_class_attribute.py:36: in __get__
    setattr(cls, self.name, self.func())
../marshmallow_dataclass/__init__.py:462: in class_schema
    return _internal_class_schema(clazz, base_schema)
../marshmallow_dataclass/__init__.py:552: in _internal_class_schema
    attributes.update(
../marshmallow_dataclass/__init__.py:555: in <genexpr>
    _field_for_schema(
../marshmallow_dataclass/__init__.py:855: in _field_for_schema
    generic_field = _field_for_generic_type(typ, base_schema, **metadata)
../marshmallow_dataclass/__init__.py:711: in _field_for_generic_type
    from . import union_field
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    import copy
    import inspect
    from typing import List, Tuple, Any, Optional
    
    import typeguard
    from marshmallow import fields, Schema, ValidationError
    
    try:
        from typeguard import TypeCheckError  # type: ignore[attr-defined]
    except ImportError:
        # typeguard < 3
        TypeCheckError = TypeError  # type: ignore[misc, assignment]
    
>   if "argname" not in inspect.signature(typeguard.check_type).parameters:
E   AttributeError: module 'typeguard' has no attribute 'check_type'

../marshmallow_dataclass/union_field.py:14: AttributeError
@jasle
Copy link
Contributor Author

jasle commented May 9, 2024

I see two options to fix this:

  1. Obviously adding a explicit message when trying to use Unions but typeguard is not available.
  2. Make typeguard a non-extra dependency. If marshmallow_dataclass drops support for older python versions (as suggested in PR Update depedency typeguard #260) and the minimum version of marshmallow is raised from 3.13 to 3.18 this would allow to completely refrain from using extra dependencies.

What do you think @lovasoa?

@lovasoa
Copy link
Owner

lovasoa commented May 10, 2024

Yes, i think we should go with option 2.

@jasle
Copy link
Contributor Author

jasle commented May 11, 2024

Closed by #263

@jasle jasle closed this as completed May 11, 2024
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

2 participants