[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2020-01-19 Thread Guido van Rossum
Guido van Rossum added the comment: In the example, it should be `int`, right? Anyway, the bug tracker is not a good place to get questions answered. Since this is mostly about type checking, I recommend that you try this Gitter instance: https://gitter.im/python/typing --

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2020-01-18 Thread Alexander Hirner
Alexander Hirner added the comment: In that case, what should the getter return? It doesn't know about the implementation of x. Maybe I'm not getting the idea behind adding getters/setters. -- ___ Python tracker

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2020-01-02 Thread Guido van Rossum
Guido van Rossum added the comment: No doubt because your getter returns None. -- ___ Python tracker ___ ___ Python-bugs-list

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2020-01-02 Thread Alexander Hirner
Alexander Hirner added the comment: This results in E(x=None). I'd need to look into that to understand why. -- Added file: https://bugs.python.org/file48817/dc2_repro.py ___ Python tracker

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2020-01-01 Thread Guido van Rossum
Guido van Rossum added the comment: Try adding a setter to the base class method. -- ___ Python tracker ___ ___ Python-bugs-list

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2020-01-01 Thread Alexander Hirner
Alexander Hirner added the comment: Dropping ABCMeta stops at instantiation. This should be in the dataclass code that's been generated. File "", line 2, in __init__ AttributeError: can't set attribute Repro: ``` class QuasiABC: @property @abstractmethod def x(self) -> int:

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2019-12-28 Thread Guido van Rossum
Guido van Rossum added the comment: Have you tried dropping ABCMeta? Mypy checks @abstractmethod regardless. -- ___ Python tracker ___

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2019-12-28 Thread Alexander Hirner
Alexander Hirner added the comment: We construct a computational graph and need to validate (or search for possible new) edges at runtime. The data is specific to computer vision. One example is clipping geometry within 2D boundaries. A minimal implementation of this data would be:

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2019-12-27 Thread Guido van Rossum
Guido van Rossum added the comment: Thanks. Can you be specific about “modern libraries”? Please clarify your use cases. -- ___ Python tracker ___

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2019-12-27 Thread Alexander Hirner
Alexander Hirner added the comment: Pardon my sloppiness. 1. That should have been PEP 544. The last point referred to the notion of data protocols [0]. 2. I think solving this issue for dataclasses would ensure better composition with modern libraries and other idioms like Protocol and

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2019-12-26 Thread Guido van Rossum
Guido van Rossum added the comment: 1. PEP 554 is about multiple interpreters. Which PEP did you mean? 2. The double negative in “Wouldn't it pay off to not rewrite dataclass features” is confusing. What did you mean? -- nosy: +gvanrossum ___

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2019-12-26 Thread Alexander Hirner
Alexander Hirner added the comment: Here, nothing but less boiler plate. Wouldn't it pay off to not rewrite dataclass features like frozen, replace, runtime refelection and the ability to use dataclass aware serialization libraries (e.g. pydantic)? I think @dataclass+@abstractproperty

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2019-12-26 Thread Eric V. Smith
Eric V. Smith added the comment: Is dataclasses doing something here that a regular, hand-written class wouldn't do? -- ___ Python tracker ___

[issue39134] can't construct dataclass as ABC (or runtime check as data protocol)

2019-12-25 Thread Alexander Hirner
New submission from Alexander Hirner : At runtime, we want to check whether objects adhere to a data protocol. This is not possible due to problematic interactions between ABC and @dataclass. The attached file tests all relevant yet impossible cases. Those are: 1) A(object): Can't check due