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.

classification
Title: Empty Strings are not parsed to None.
Type: behavior Stage: resolved
Components: Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Decorater, ethan.furman
Priority: normal Keywords:

Created on 2016-09-10 23:27 by Decorater, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg275713 - (view) Author: Decorater (Decorater) * Date: 2016-09-10 23:27
I noticed that the Python interpreter does not interpret a empty string as None so I have to do this unclean workaround every time in functions that cannot have a empty string passed to them.

Here is some example Code I have to do to bypass this (the function itself):

def create_one(url):
    if url == '':
        url = None
    if url is not None:
        url_data = urllib.parse.urlencode(dict(url=url))
        byte_data = str.encode(url_data)
        ret = urllib.request.urlopen(API_CREATE, data=byte_data).read().strip()
        almost_result = str(ret)
        closer_result = almost_result.strip("b")
        result = closer_result.strip("'")
        return result
    else:
        URLError('The given URL Cannot be \'None\'.')

So yeah I suggest for the interpreter to interpret empty strings as None so that way it can cleanup some lines of trying to parse it to None which can be a lot of work. It also makes code simpler as well.
msg275714 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-09-10 23:32
Empty strings are empty strings, not None.

An better way for your code example would be:

def ...():
    if url:
       ....
    else:
       raise URLError(...URL cannot be empty...)
History
Date User Action Args
2022-04-11 14:58:36adminsetgithub: 72259
2016-09-10 23:32:37ethan.furmansetstatus: open -> closed

type: behavior

nosy: + ethan.furman
messages: + msg275714
resolution: not a bug
stage: resolved
2016-09-10 23:28:22Decoratersetversions: + Python 3.5, Python 3.6
2016-09-10 23:27:30Decoratercreate