Author ezio.melotti
Recipients ajaksu2, brian.curtin, denversc, dstanek, eric.araujo, ezio.melotti, ipatrol, jackdied, jjlee, jorend, koder_ua, orsenthil, pitrou, poke, santoso.wijaya
Date 2011-10-11.03:56:51
SpamBayes Score 2.37171e-12
Marked as misclassified No
Message-id <1318305413.17.0.412047106446.issue1673007@psf.upfronthosting.co.za>
In-reply-to
Content
We have discussed the API a bit on IRC and these are the outcomes:

1) should method always have priority or should 'POST' always be used whenever data is passed?
2) if the method is e.g. 'GET' and data is passed, should an error be raised?
3) should Request.method be private?
4) should the value of Request.method be initialized in the __init__ or can it also be None?
5) if the value of Request.method is always initialized, should we deprecate get_method?

IMHO

  r = Request(url, data, method=foo)

should behave like

  class FooRequest(Request):
      def get_method(self):
          return foo
  r = FooRequest(url, data)

when foo is not None and

  class FooRequest(Request): pass
  r = FooRequest(url, data)

when foo is None, so the answers to the 5 questions would be

1) method always has the highest priority, data is used to decide between GET and POST when method is None;
2) data is simply ignored if the method doesn't use it -- no errors are raised;
3) maybe, currently is not (see below);
4) method matches the value passed to the constructor, defaulting to None;
5) since it's not initialized, get_method shouldn't be deprecated;

This is also what the patch implements.

Regarding 3), one might look at Request.method and see None instead of GET/POST, and this might be confusing.  We could document that get_method() should be used instead to see what method will be actually used or make Request.method private and avoid the problem.  If we do so there won't be a way to change the method after instance creation (but that wasn't even supported before[0], so it's probably not a problem).  OTOH, the other args (e.g. data) are available and documented.  I'm fine with either documenting that get_method() should be used instead or making Request.method private.

Another approach is to move the get_method() logic in the __init__, set self.method to method (if specified) or either POST (if there are data) or GET.  Then have get_method() simply return self.method (and possibly deprecate it).

[0]: it's actually possible to replace the get_method() method, but if Request.method is public one could set it to a new value or to None to restore the normal behavior (GET or POST depending on data).
History
Date User Action Args
2011-10-11 03:56:53ezio.melottisetrecipients: + ezio.melotti, jjlee, jorend, orsenthil, pitrou, dstanek, jackdied, ajaksu2, koder_ua, eric.araujo, brian.curtin, poke, ipatrol, santoso.wijaya, denversc
2011-10-11 03:56:53ezio.melottisetmessageid: <1318305413.17.0.412047106446.issue1673007@psf.upfronthosting.co.za>
2011-10-11 03:56:52ezio.melottilinkissue1673007 messages
2011-10-11 03:56:51ezio.melotticreate