-
Notifications
You must be signed in to change notification settings - Fork 382
Consider tightening arguments that are dynamic
#375
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
Comments
Maybe annotate the old method signature as obsolete and add a new one that only takes a Uri. |
Adding an alternative would be the typical upgrade route. In this case it would likely leave us with less desirable naming and wouldn't save much cost in the migration. The vast majority of this will be caught statically and the migration is trivial so it doesn't really need an long rollout. |
Another alternative that came up today would be to add an extension on the extension Http on Uri {
Future<Response> get({Map<String, String> headers}) => get(this, headers: headers);
} This allows for static safety through this api, without conflicting with the existing api. To accomodate strings we could add a
So final usage is like |
Prepare for dart-lang/http#375
Prepare for dart-lang/http#375
Prepare for dart-lang/http#375
Prepare for dart-lang/http#375
Prepare for dart-lang/http#375
Prepare for dart-lang/http#375
Fixes #375 Make all arguments that were `Object` in order to allow either `String` or `Uri` accept only `Uri`. This gives better static checking for calling code.
Prepare for dart-lang/http#375
Prepare for dart-lang/http#375
Prepare for dart-lang/http#375
Prepare for dart-lang/http#375
Pass a Uri to package:http APIs; prepare for dart-lang/http#375
Prepare for dart-lang/http#375
This is in preparation for dart-lang/http#375
Prepare for dart-lang/http#375 This was missed in #86 for one test but missed here since this file had not yet been imported to google3 when I looked for cases.
Prepare for dart-lang/http#375 This was fixed in #86 for one test but missed here since this file had not yet been imported to google3 when I looked for cases.
Hm, to be honest I really like the convenience with using a String as an URL. I think both approaches have pros and cons. In my opinion the real fix would be to wait until there are better ways to express unions - with the current dynamic approach there may not even be breaking changes when unions do finally happen in the future ( In the end I guess you'll already have made up your mind so idk. Just seems like a big breaking change for me with some amount of "unnecessary" cruft work (adding |
Ya, it is a fairly impactful breaking change, but the migration is very mechanical and you get static errors for all the places that need to be fixed up. We found a lot of evidence when examining existing code that the existing api was very confusing to folks - many appeared to think it only accepts a String. This lead to a lot of sub-optimal code (several instances of code converting a Uri to a String just to pass it into these functions for instance). Also a lot of people attempting to do their own uri escaping in strings, which if they just used the Uri class to build it up they would not have had to do, etc (not to mention this was never done exhaustively). People were also building up uris in very inconsistent and fragile ways. This won't prevent them from doing that (a common migration will likely involve a simple conversion to use So, those are some of the motivations for this change. |
Thank you for clarifying:) |
Closes #375 Make all arguments that were `Object` in order to allow either `String` or `Uri` accept only `Uri`. This gives better static checking for calling code.
…ter#3309) This is in preparation for dart-lang/http#375
…ter#3309) This is in preparation for dart-lang/http#375
Pass a Uri to package:http APIs; prepare for dart-lang/http#375
The
dynamic url
which may be either aString
orUri
is not an idiomatic pattern in Dart 2. You lose static checking and are forced to read the doc comment to get help with usage that is normally provided in your IDE. The migration would be easy, shift theUri.parse
call to the call site instead of inside the library code.The downside here is that there is potentially a lot of code to migrate since this is such a widely used package. That is mitigated somewhat by the fact that you'll get static checking for the migration in the vast majority of cases, only dynamic invocations would be runtime failures.
The text was updated successfully, but these errors were encountered: