#33199: Deprecate passing positional arguments to Signer.
-------------------------------------+-------------------------------------
     Reporter:  Daniel Samuels       |                    Owner:  Nikita
                                     |  Marchant
         Type:  New feature          |                   Status:  assigned
    Component:  Core (Other)         |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Jacob Walls):

 I think prepending `*args` before the existing arguments is good, but if
 you can avoid tinkering with `locals()`, the better, I think.

 What about something like:

 {{{
 diff --git a/django/core/signing.py b/django/core/signing.py
 index 5ee19a9336..724a7df507 100644
 --- a/django/core/signing.py
 +++ b/django/core/signing.py
 @@ -37,10 +37,12 @@ import base64
  import datetime
  import json
  import time
 +import warnings
  import zlib

  from django.conf import settings
  from django.utils.crypto import constant_time_compare, salted_hmac
 +from django.utils.deprecation import RemovedInDjango50Warning
  from django.utils.encoding import force_bytes
  from django.utils.module_loading import import_string
  from django.utils.regex_helper import _lazy_re_compile
 @@ -145,16 +147,25 @@ def loads(s, key=None, salt='django.core.signing',
 serializer=JSONSerializer, ma


  class Signer:
 -    def __init__(self, key=None, sep=':', salt=None, algorithm=None):
 +    def __init__(self, *args, key=None, sep=':', salt=None,
 algorithm=None):
          self.key = key or settings.SECRET_KEY
          self.sep = sep
 +        self.salt = salt or '%s.%s' % (self.__class__.__module__,
 self.__class__.__name__)
 +        self.algorithm = algorithm or 'sha256'
 +        if args:
 +            warnings.warn(
 +                'Providing positional arguments to Signer is
 deprecated.',
 +                RemovedInDjango50Warning,
 +                stacklevel=2,
 +            )
 +            for arg, attr in zip(args, ['key', 'sep', 'salt',
 'algorithm']):
 +                if arg or attr == 'sep':
 +                    setattr(self, attr, arg)
          if _SEP_UNSAFE.match(self.sep):
              raise ValueError(
                  'Unsafe Signer separator: %r (cannot be empty or consist
 of '
                  'only A-z0-9-_=)' % sep,
              )
 -        self.salt = salt or '%s.%s' % (self.__class__.__module__,
 self.__class__.__name__)
 -        self.algorithm = algorithm or 'sha256'


 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33199#comment:11>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.1f169094f9e275c35b2dbafb5e121d6b%40djangoproject.com.

Reply via email to