-
Notifications
You must be signed in to change notification settings - Fork 341
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
Make callback defs types less restrictive #364
Make callback defs types less restrictive #364
Conversation
An alternative approach would be to add |
@ryanwinchester I like the |
@edgurgel moved it to request struct properties' types |
c5a6c5c
to
bd14138
Compare
@type params :: map | keyword | [{binary, binary}] | ||
@type options :: keyword | ||
@type headers :: [{atom, binary}] | [{binary, binary}] | %{binary => binary} | any | ||
@type url :: binary | any |
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.
now that I'm reading this we will accept any
for the result of process_request_url
right? 🤔
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.
Technically we want anything that implements String.Chars
protocol (i.e. can work with to_string/1
), but we can't really spec for protocols, so... we're kinda forced to give suggestions, and then include any
on the end, imo
Same could be said for some of the other properties, too.
For example the :body
we can expect {:stream, enumerable}
but can't really spec for the Enumerable protocol, so... any
:/
Anyways, they can technically pass any
where any of the properties have an associated process_x
function and they implement it and return the expected type.
We could make it more obvious if we do:
@callback process_request_url(any) :: url
@spec process_request_url(any) :: url
def process_request_url(url), do: process_url(url)
instead of
@callback process_request_url(url) :: url
@spec process_request_url(url) :: url
def process_request_url(url), do: process_url(url)
(even though they'd really be the same effect in the end, it's just visual)
Thoughts?
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.
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.
Oh I agree with any for the input. I'm wondering about the return being url
as any
is also acceptable 🤔
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.
@edgurgel with this change url
includes | any
;)
So really we can put either, but i feel like using url
in the return conveys the intention better, even though it doesn't really matter
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.
However, I'm fine either way, just let me know which you want and where.
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.
That's fine then 👍
This builds on PR #363 and probably fixes #327
Examples
I used the format
when I could have used a simpler
for the sake of code as documentation, but we can just use the simpler version if you prefer.
Reasoning
The reasoning behind these changes is that you really can pass anything in as long as your
process_*
override returns the proper type.See the return type: