Skip to content

isinstance(filename, "utf-8") #304

Description

Activity

  1. aclark4life commented on Jul 25, 2013

    @aclark4life
    Member

    Not sure what you are asking for but you are welcome to send a pull request

  2. mnowotka commented on Jul 25, 2013

    @mnowotka
    ContributorAuthor

    Easy - according to content of the error, the second argument of isinstance can't be string (i.e. 'utf-8'). 'isinstance' is not the way how you check file encoding. I'm not sure what is a propper way (that's why I asked it on SO) but the current implementation is clearly wrong.

  3. aclark4life commented on Jul 25, 2013

    @aclark4life
    Member

    How about isinstance(filename, unicode) ? (HT: @mjpieters)

  4. mjpieters commented on Jul 25, 2013

    @mjpieters
    Contributor

    isinstance(filename, str) should work. It is not isinstance() and the code is trying to convert it to str because that is the right type for both Python 2 and 3 here.

  5. mnowotka commented on Jul 25, 2013

    @mnowotka
    ContributorAuthor

    https://enjoydoingitwrong.wordpress.com/2009/06/22/unicode-is-not-utf/
    so I'm not sure if you want to check encoding (in that case isinstance(filename, unicode) is not the answer) or just check if the content is instance of basestring or unicode.

  6. mnowotka commented on Jul 25, 2013

    @mnowotka
    ContributorAuthor

    @mjpieters - if you know it for sure, can you change it?

  7. aclark4life commented on Jul 25, 2013

    @aclark4life
    Member

    @mnowotka You can change it by sending a pull request 😃

  8. added a commit that references this issue on Jul 25, 2013
  9. wiredfool commented on Jul 25, 2013

    @wiredfool
    Member

    That (original) code looks like a double encoding bug waiting to happen.

  10. mjpieters commented on Jul 25, 2013

    @mjpieters
    Contributor

    @wiredfool: No, it's fine; Python 2 not str means unicode, so it needs to be encoded, in Python 3, not str means bytes, so it needs to be decoded.

  11. added a commit that references this issue on Jul 25, 2013
  12. wiredfool commented on Jul 25, 2013

    @wiredfool
    Member

    @mjpieters fair enough.

  13. added a commit that references this issue on Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions