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

Option to get None instead of empty string #44

Closed
Xennis opened this issue Mar 18, 2016 · 9 comments
Closed

Option to get None instead of empty string #44

Xennis opened this issue Mar 18, 2016 · 9 comments
Milestone

Comments

@Xennis
Copy link

Xennis commented Mar 18, 2016

Hey,

is there an option to get None instead of an empty string for the components? E.g.

>>> name = HumanName("1 & 2, 3 4 5, Mr.")
>>> name.title
None
>>>name.first
'3'
@derek73
Copy link
Owner

derek73 commented Mar 18, 2016

There is not. Currently it returns the value from " ".join([]), which is an empty string. It would be pretty easy to make it do that though. Of course, you could do it easily too with something like name.title or None, but maybe there's some case where that's inconvenient? Idk, maybe it would be fine to make it always return None instead of an empty string? I don't have a strong preference.

@Xennis
Copy link
Author

Xennis commented Mar 19, 2016

For instance when you store the name components in a database and you want to store that values as NULL and not as empty string, it's easier when the module directly returns None.

@derek73 derek73 added this to the v0.3.14 milestone Mar 19, 2016
@derek73
Copy link
Owner

derek73 commented Mar 19, 2016

Turns out the change breaks a bunch of tests, mostly to do with string formatting, so I just added a configuration option for it, documented here:

http://nameparser.readthedocs.org/en/latest/modules.html#nameparser.config.Constants.empty_attribute_default

@Xennis
Copy link
Author

Xennis commented Mar 19, 2016

Maybe it's an idea to modify line 122: Do a .replace(CONSTANTS.empty_attribute_default, "") first; since you probably don't want to have an output like 'None John None Doe None (None)' when printing the hole name.

@derek73
Copy link
Owner

derek73 commented Mar 19, 2016

Thanks for the suggestion. I gave it a shot but my attempt doesn't pass the test. I made a branch and pull request: #45

Here's the failed Travis build:
https://travis-ci.org/derek73/python-nameparser/builds/117161574

@derek73
Copy link
Owner

derek73 commented Mar 19, 2016

I figured it out. It was a problem with the tests and me forgetting how to use my own software.

@derek73
Copy link
Owner

derek73 commented Mar 19, 2016

I posted the results of the tests when CONSTANTS.empty_attribute_default = None over on the pull request. Take a look and let me know if you think there's something better we could do or maybe it's all fine.

@Xennis
Copy link
Author

Xennis commented Mar 20, 2016

Thanks for you friendly support. I am now using this module for some days and it is quite nice.

The code changes looks fine.

Maybe they are all just problems with the tests, because its explicitly testing for '' instead of hn.C.empty_attribute_default?

I think you are right. Probably you should test for hn.C.empty_attribute_default instead.

derek73 added a commit that referenced this issue Mar 21, 2016
remove default attribute from formatted string (#44)
@derek73
Copy link
Owner

derek73 commented Mar 21, 2016

Just released v0.3.15 that should take care of all this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants