This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients docs@python, gvanrossum, jaraco, terry.reedy
Date 2020-08-29.19:52:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1598730752.07.0.899029021208.issue41615@roundup.psfhosted.org>
In-reply-to
Content
The docs are normative as well as descriptive.  The specific doc for sys.argv is https://docs.python.org/3/library/sys.html#sys.argv.  It says that a proper Python stdlib sys module has an args attribute that is a non-empty list whose first item is a string.  (It implies, and to me should actually say, that all items are strings.)  Since it would seem that it is easy enough to make this true, I think that Python code should be able to depend on this as much as anything else in the docs.

The 2003 issue 839151 reported that warnings.warn exited with AttributeError when accessing a non-existent argv in an embedded interpreter.  I presume that the latter was embedded CPython.  AFAIK, the fix could have been to fix embedded interpreters to have sys.argv = ['']. (My preference.) Instead, the fix, for the warn access only, was to guard the access with try-except AttributeError.

The extended fix proposed here is to document that argv is at least optional and therefore imply that all access should be wrapped in try-except.

Guido, which idea comports with your idea of 'Python': sys has an argv with at least one string (the name, if any, of a 'program'); or sys has an optional argv, so that all bullet-proof code must guard access by catching at least AttributeError?
---

Notes on a couple of #839151 messages:

1. The fact that one can make argv be missing by deleting it was and is irrelevant.  Monkeypatching modules by deleting and changing attributes can create unlimited havoc and there is nothing special about sys.argv in this regard.

2. "this [patch] should also catch IndexError and TypeError in case sys.argv is an empty list or it is not even a list at all."  I consider this similarly irrelevant because both of these would, according to the doc, be bugs, whether originally present or introduced by monkeypatching.  

https://github.com/pypa/keyring/445 is 404 for me in multiple tries.
History
Date User Action Args
2020-08-29 19:52:32terry.reedysetrecipients: + terry.reedy, gvanrossum, jaraco, docs@python
2020-08-29 19:52:32terry.reedysetmessageid: <1598730752.07.0.899029021208.issue41615@roundup.psfhosted.org>
2020-08-29 19:52:32terry.reedylinkissue41615 messages
2020-08-29 19:52:31terry.reedycreate