GithubHelp home page GithubHelp logo

Comments (9)

Tinche avatar Tinche commented on May 18, 2024

Acknowledged, will look into this :)

from cattrs.

anthrotype avatar anthrotype commented on May 18, 2024

Thanks 👍

from cattrs.

madsmtm avatar madsmtm commented on May 18, 2024

From what I can tell this is fixed in 0460fbe

from cattrs.

zhukovgreen avatar zhukovgreen commented on May 18, 2024

it looks like the problem still persists and it is more generic one:

from typing import Tuple, Set
from datetime import datetime

import cattr
import attr
import pytest


TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
COMPLEX_TYPE = Tuple[Tuple[str, datetime]]
COMPLEX_TYPE_BAD = Set[Tuple[str, datetime]]

cattr.register_unstructure_hook(
    datetime, lambda dt: datetime.strftime(dt, format=TIME_FORMAT)
)
cattr.register_structure_hook(
    datetime, lambda dt_str, _: datetime.strptime(dt_str, TIME_FORMAT)
)


def test_cattrs_io_for_a():
    @attr.s(auto_attribs=True)
    class A:
        ds: datetime = attr.ib(factory=datetime.utcnow)

    a = A()
    a_ser = cattr.unstructure(a)
    a_des = cattr.structure(a_ser, A)
    assert isinstance(a_des, A)


def test_cattrs_io_for_b():
    @attr.s(auto_attribs=True)
    class B:
        ds: COMPLEX_TYPE = attr.ib(factory=set)

    b = B((("a", datetime.utcnow()), ("b", datetime.utcnow())))
    b_ser = cattr.unstructure(b)
    b_des = cattr.structure(b_ser, B)
    assert isinstance(b_des, B)


def test_cattrs_io_for_b_bad():
    @attr.s(auto_attribs=True)
    class B:
        ds: COMPLEX_TYPE_BAD = attr.ib(factory=set)

    b = B({("a", datetime.utcnow()), ("b", datetime.utcnow())})
    b_ser = cattr.unstructure(b)
    with pytest.raises(TypeError):
        b_des = cattr.structure(b_ser, B)
        assert isinstance(b_des, B)

COMPLEX_TYPE_BAD isnot being unstructured

cattrs==0.9.0

from cattrs.

madsmtm avatar madsmtm commented on May 18, 2024

The fix hasn't yet been released. Please try running this from the current master

from cattrs.

zhukovgreen avatar zhukovgreen commented on May 18, 2024

Thx

from cattrs.

bhargavrpatel avatar bhargavrpatel commented on May 18, 2024

Hello -- Just following up on this. Is this deployed PyPi?

from cattrs.

zhukovgreen avatar zhukovgreen commented on May 18, 2024

@bhargavrpatel the issue is still valid. Just tested it

from cattrs.

Tinche avatar Tinche commented on May 18, 2024

This has been fixed for a long time I believe, so closing.

from cattrs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.