Repository: nithinmurali/pygsheets

Issue:
RuntimeError: dictionary changed size during iteration
https://github.com/nithinmurali/pygsheets/blob/0e2468fe9a1957b19f1cebe3667c601c32942bbd/pygsheets/authorization.py#L94

You can't delete keys from a dictionary you are currently iterating.

Discussion:

Patch:
diff --git a/.gitignore b/.gitignore
index 9bc512f..3556492 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,22 +1,28 @@
+# Python
 *.pyc
-.DS_Store
-.coverage
-
+build/
+dist/
 venv/
-.idea/
 .cache/
 .pytest_cache/
-build/
-dist/
-# docs/
+pygsheets.egg-info/
+.pytest_cache/
+
+# File types
 *.json
 *.csv
+
+# Tests
 test/*.json
 test/usages
 test/data/*.json
 test/manual_test1.py
-pygsheets.egg-info/
 
+# Other
+.idea/
+.DS_Store
+.python-version
+.coverage
 
 
 
diff --git a/pygsheets/authorization.py b/pygsheets/authorization.py
index 6c1b37f..0d4420b 100644
--- a/pygsheets/authorization.py
+++ b/pygsheets/authorization.py
@@ -59,7 +59,6 @@ _SCOPES = ('https://www.googleapis.com/auth/spreadsheets', 'https://www.googleap
 _deprecated_keyword_mapping = {
     'outh_file': 'client_secret',
     'outh_creds_store': 'credentials_directory',
-    'outh_nonlocal': 'non_local_authorization',
     'service_file': 'service_account_file',
     'credentials': 'custom_credentials'
 }
@@ -86,13 +85,15 @@ def authorize(client_secret='client_secret.json',
     :param kwargs:                  Parameters to be handed into the client constructor.
     :returns:                       :class:`Client`
     """
-    v = vars()
+
     for key in kwargs:
         if key in ['outh_file', 'outh_creds_store', 'service_file', 'credentials']:
             warnings.warn('The argument {} is deprecated. Use {} instead.'.format(key, _deprecated_keyword_mapping[key])
                           , category=DeprecationWarning)
-            v[_deprecated_keyword_mapping[key]] = kwargs[key]
-            del kwargs[key]
+    client_secret = kwargs.get('outh_file', client_secret)
+    service_account_file = kwargs.get('service_file', service_account_file)
+    credentials_directory = kwargs.get('outh_creds_store', credentials_directory)
+    custom_credentials = kwargs.get('credentials', custom_credentials)
             
     if custom_credentials is not None:
         credentials = custom_credentials


Test patch:
diff --git a/test/authorization_tests.py b/test/authorization_tests.py
index eee5b06..16389cb 100644
--- a/test/authorization_tests.py
+++ b/test/authorization_tests.py
@@ -26,4 +26,8 @@ class TestAuthorization(object):
 
         self.sheet = c.create('test_sheet')
         self.sheet.share('pygsheettest@gmail.com')
-        self.sheet.delete()
\ No newline at end of file
+        self.sheet.delete()
+
+    def test_deprecated_kwargs_removal(self):
+        c = pygsheets.authorize(service_file=self.base_path + '/pygsheettest_service_account.json')
+        assert isinstance(c, Client)
\ No newline at end of file