Skip to content

basestring doesn't work in Python 3 #4

@Ayehavgunne

Description

@Ayehavgunne

After attempting to use user-agents with Python 3 I got a NameError due to the use of basestring. I put this in to quickly get it working (for me at least with a minimum of testing).

    try:
        if major is not None and isinstance(major, basestring):
            major = int(major) if major.isdigit() else major
    except NameError:
        if major is not None and isinstance(major, str):
            major = int(major) if major.isdigit() else major
    try:
        if minor is not None and isinstance(minor, basestring):
            minor = int(minor) if minor.isdigit() else minor
    except NameError:
        if minor is not None and isinstance(minor, str):
            minor = int(minor) if minor.isdigit() else minor
    try:
        if patch is not None and isinstance(patch, basestring):
            patch = int(patch) if patch.isdigit() else patch
    except NameError:
        if patch is not None and isinstance(patch, str):
            patch = int(patch) if patch.isdigit() else patch
    try:
        if patch_minor is not None and isinstance(patch_minor, basestring):
            patch_minor = int(patch_minor) if patch_minor.isdigit() else patch_minor
    except NameError:
        if patch_minor is not None and isinstance(patch_minor, str):
            patch_minor = int(patch_minor) if patch_minor.isdigit() else patch_minor

Which replaces this starting at line 40

    if major is not None and isinstance(major, basestring):
        major = int(major) if major.isdigit() else major
    if minor is not None and isinstance(minor, basestring):
        minor = int(minor) if minor.isdigit() else minor
    if patch is not None and isinstance(patch, basestring):
        patch = int(patch) if patch.isdigit() else patch
    if patch_minor is not None and isinstance(patch_minor, basestring):
        patch_minor = int(patch_minor) if patch_minor.isdigit() else patch_minor

I am sure there is a more elegant fix that I am not going to bother looking up this late at night. I might come back to this later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions