-
Notifications
You must be signed in to change notification settings - Fork 40
Implement SizedSliceable protocol in src/graphql_relay/connection/arrayconnection.py #31
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Maybe we can already merge it, when we require the typing_extensions only for the older Python versions.
Alternatively, we could not require typing_extensions and fall back to Protocol=Sequence if Protocol does not exist in typing.
3abdca5
to
94a10f0
Compare
94a10f0
to
a413c50
Compare
I've made the requested changes, @Cito. Some notes:
|
Looks good to me, I just had one question. Regarding poetry, you only need to run |
Re: poetry, I just wasn't sure if I needed to do anything other than add |
I meant the question why you added a bare asterisk to the parameter list in one place (and not the others). |
Weird, I don't see where you originally asked the asterisk question. So, the reason for the bare asterisk is that I need to make the A simpler approach would be to scrap the overloads altogether and just have the runtime enforcement (i.e. a crash if a plain Do you have a suggestion to do this more elegantly? |
@overload | ||
def connection_from_array_slice( | ||
array_slice: Sliceable, | ||
*, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you added a bare asterisk here (and not in the other overload)?
Sorry, forgot to finish the review, so the question was not visible. |
Ok, right, if you remove the |
Yeah. Like I said, this isn't a very satisfying solution. My temptation is to rework the signatures of the |
Maybe we can put the asterisk a bit further down the road, directly before the Or just remove it and rely on the runtime error? I don't really like that we restrict usage with positional args in one form and not the other, just because of typing issues. But then the whole overloading and distinguishing the two scliceable types makes no sense any more. |
Btw, if you have the energy to work on improving the typing issues, you can consider to add these to mypy.ini and make the appropriate changes (in a separate PR of course):
These have also been added to Graphql-core, so this would achieve more consistency. |
I experimented with that, and it seems even more arbitrary to me. Actually, to do this correctly with
I think the best thing to do here is ditch the |
Ok, yes, let's keep it simple. For the sake of: Beautiful is better than ugly. Simple is better than complex. Readability counts. Unfortunately, Python type hints are not only a blessing but also a curse. Code that once looked so clean, short and simple, starts to look bloated and complicated when with all these type hints, sometimes even worse than in statically typed languages that we try to imitate. |
Yeah, my opinion is type hints should always improve code understandability. That's one of their major functions, IMO. They shouldn't be allowed to cross that line and make the code harder to work with. Will update the PR. |
a413c50
to
e08939a
Compare
Resolves #29