Code Monkey home page Code Monkey logo

Comments (6)

jdlc avatar jdlc commented on August 15, 2024

@alanhamlett,
Thanks for opening this issue. Could you share more details about your use case and integration with Braintree so we can better evaluate this change? Currently the Braintree Python client library as a whole favors str over basestring.

from braintree_python.

alanhamlett avatar alanhamlett commented on August 15, 2024

Sometimes I pass strings from SQLAlchemy, which prefers unicode over str, and from WTForms, which also prefers unicode over str. I'm not sure which attribute caused the error, but it was when changing the quantity in the addons array when updating a subscription.

from braintree_python.

jdlc avatar jdlc commented on August 15, 2024

Thanks for clarifying your use case. We'll discuss this change and let you know if we have any further questions.

from braintree_python.

jdlc avatar jdlc commented on August 15, 2024

Hi @alanhamlett,
We've discussed this internally and we will be retaining str as we want encoded strings instead of unicode. I'm closing this issue, but thanks for reaching out.

from braintree_python.

alanhamlett avatar alanhamlett commented on August 15, 2024

Ok, just want to say that str should only be used when writing to disk, network, or other things external to Python. unicode is the preferred way to handle any string in Python.

When you’re dealing with text manipulations (finding the number of characters in a string or cutting a string on word boundaries) you should be dealing with unicode strings as they abstract characters in a manner that’s appropriate for thinking of them as a sequence of letters that you will see on a page. When dealing with I/O, reading to and from the disk, printing to a terminal, sending something over a network link, etc, you should be dealing with byte str as those devices are going to need to deal with concrete implementations of what bytes represent your abstract characters.

For example as soon as you get a string from the user or from the network, convert it to unicode:
https://pythonhosted.org/kitchen/unicode-frustrations.html#convert-text-at-the-border
I've noticed usage of both unicode and str in this library. You should standardize the usage of unicode vs str throughout the library.

You're going to run into a lot of cases where unicode is needed (emails can contain unicode characters) so it's best to standardize on unicode instead of str. Having to somehow guess which string type this library is expecting is a recipe for exceptions.

from braintree_python.

alanhamlett avatar alanhamlett commented on August 15, 2024

Also, the 2 most popular Python web frameworks[1] both default to unicode and both convert user input to unicode. For example a payment processor token from braintree.js is automatically treated as unicode and it goes against conventions to have to convert back to str when passing strings to braintree_python.

  1. Django and Flask are in my experience the 2 most popular Python web frameworks

from braintree_python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.