Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty Strings are not parsed to None. #72259

Closed
AraHaan mannequin opened this issue Sep 10, 2016 · 2 comments
Closed

Empty Strings are not parsed to None. #72259

AraHaan mannequin opened this issue Sep 10, 2016 · 2 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@AraHaan
Copy link
Mannequin

AraHaan mannequin commented Sep 10, 2016

BPO 28072
Nosy @ethanfurman, @AraHaan

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-09-10.23:32:37.550>
created_at = <Date 2016-09-10.23:27:30.298>
labels = ['type-bug', 'invalid']
title = 'Empty Strings are not parsed to None.'
updated_at = <Date 2016-09-10.23:32:37.548>
user = 'https://github.com/AraHaan'

bugs.python.org fields:

activity = <Date 2016-09-10.23:32:37.548>
actor = 'ethan.furman'
assignee = 'none'
closed = True
closed_date = <Date 2016-09-10.23:32:37.550>
closer = 'ethan.furman'
components = []
creation = <Date 2016-09-10.23:27:30.298>
creator = 'Decorater'
dependencies = []
files = []
hgrepos = []
issue_num = 28072
keywords = []
message_count = 2.0
messages = ['275713', '275714']
nosy_count = 2.0
nosy_names = ['ethan.furman', 'Decorater']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue28072'
versions = ['Python 3.5', 'Python 3.6']

@AraHaan
Copy link
Mannequin Author

AraHaan mannequin commented Sep 10, 2016

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.

@ethanfurman
Copy link
Member

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...)

@ethanfurman ethanfurman added invalid type-bug An unexpected behavior, bug, or error labels Sep 10, 2016
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant