[PATCH 3 of 8] url: remove is-comparisons with non-singletons

Martin Geisler mg at lazybytes.net
Tue Nov 16 22:57:51 UTC 2010


Dan Villiom Podlaski Christiansen <danchr at gmail.com> writes:

> # HG changeset patch
> # User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
> # Date 1289939758 -3600
> # Branch stable
> # Node ID 72e7c8769e4bb6cbfec1e796fd06e3416da51b26
> # Parent  b5093e797e19679cc8e7b01a7fd41feba94c6c27
> url: remove is-comparisons with non-singletons.
>
> There are two types of is-comparisons in this file:
>
> The first one is unnessecary as _GLOBAL_DEFAULT_TIMEOUT is an
> unspecialized object, and thus has no notion of equality other than
> its identity.

Using a new object() as a sentinel to detect when a keyword argument is
passed or not is a somewhat common Python idiom. I don't think we should
change it -- the code is correct as it is.

> The second one, in the auth handlers, seem unnecessary as well. The
> urllib2.Request type does not provide an equality implementation, so
> regular comparison should fall back to the exact same semantics.

Yes, but there is no advantage to this fallback -- I find the code clear
as it is: it is storing the req object it sees and only resets the
counter when a new, different req object is used.

> [1] <http://docs.python.org/c-api/int.html#PyInt_FromLong>
>
> diff --git a/mercurial/url.py b/mercurial/url.py
> --- a/mercurial/url.py
> +++ b/mercurial/url.py
> @@ -318,7 +318,7 @@ if has_https:
>                  sock = None
>                  try:
>                      sock = socket.socket(af, socktype, proto)
> -                    if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
> +                    if timeout != _GLOBAL_DEFAULT_TIMEOUT:
>                          sock.settimeout(timeout)
>                      if source_address:
>                          sock.bind(source_address)
> @@ -593,7 +593,7 @@ class httpdigestauthhandler(urllib2.HTTP
>  
>      def http_error_auth_reqed(self, auth_header, host, req, headers):
>          # Reset the retry counter once for each request.
> -        if req is not self.retried_req:
> +        if req != self.retried_req:
>              self.retried_req = req
>              self.retried = 0
>          # In python < 2.5 AbstractDigestAuthHandler raises a ValueError if
> @@ -621,7 +621,7 @@ class httpbasicauthhandler(urllib2.HTTPB
>  
>      def http_error_auth_reqed(self, auth_header, host, req, headers):
>          # Reset the retry counter once for each request.
> -        if req is not self.retried_req:
> +        if req != self.retried_req:
>              self.retried_req = req
>              self.retried = 0
>          return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

-- 
Martin Geisler

Mercurial links: http://mercurial.ch/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20101116/181b389c/attachment.asc>


More information about the Mercurial-devel mailing list