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
Underspecified result type of EZPackOverlay._ez_unpack_auth
and EZPackOverlay._ez_unpack_noauth
#1094
Comments
Strictly speaking, it is not correct to even assign a type---at all---to a dataclass. I made up this fictional type of a |
Your solution for defining Unfortunately, there is no common base class for data classes, so in Python 3.7, the correct non-generic class for a data class is But it is not critical for this PR, so if you think the |
I do agree with you that your typing proposal is stricter (and therefore better). However, my main objection is that your proposal is further reinforcing my somewhat ugly (though indeed practical) patch job of the type hierarchy. If we do change this, I'd like to see it move (more) to the ideal situation, visualized: Edit, erratum: I mislabeled the If you have time for this, I'd love to an implementation of the "ideal" situation. Otherwise, I'd prefer a reversion. Alternatively, if you have a suggestion for an even more ideal ideal, I'd love to hear other suggestions for the type hierarchy. |
I think the "Current" scheme on the left does not reflect how the current code looks. I'd say it's something like that: The left "Current" diagram assumes that The right "Ideal" diagram assumes that |
It doesn't just assume that, quite literally it is exactly that: py-ipv8/ipv8/messaging/payload_dataclass.py Lines 51 to 59 in 1a25b0c
This can be used as both an arbitrary dataclass (which is not actually a class) and as a By the way, I mislabeled the |
On a side note, how you draw the arrows depends on what convention you follow. In the existing IPv8 documentation we draw arrows from a stricter subtype to a more general supertype. For instance:
Please follow this convention so we don't mix styles. |
After almost a year of inactivity, I still see no clear actionable conclusion in this issue and I'll close this. |
Currently, the type of
_ez_unpack_auth
unpacked payload is not understood correctly by PyCharm:You can see that PyCharm can only see the base Payload methods and not the methods of IntroductionRequestPayload.
In the following PR, I suggest a fix that provides the correct result type:
Also, while fixing that issue, I noticed that currently, DataclassPayload defined as
In my opinion, it is not correct to use
TypeVar
here. Type variables are for generic functions when the function result type should be derived from the function arguments'. Here,DataclassPayload
is not used for generics and does not specify that the class is related to data classes. So, as a part of a fix, I'm replacing it with a protocol that checks that the class is actually a data class.The text was updated successfully, but these errors were encountered: