Skip to content
New issue

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

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

Already on GitHub? # to your account

conditional import against six.PY2 emits error #3501

Closed
georgexsh opened this issue Apr 21, 2020 · 3 comments · Fixed by #9534 or #9619
Closed

conditional import against six.PY2 emits error #3501

georgexsh opened this issue Apr 21, 2020 · 3 comments · Fixed by #9534 or #9619

Comments

@georgexsh
Copy link

georgexsh commented Apr 21, 2020

Steps to reproduce

  1. Given following code
import six
if six.PY3:
    from urllib.parse import urlparse
else:
    from urlparse import urlparse
  1. run pylint with python2

Current behavior

[E0611(no-name-in-module), ] No name 'parse' in module 'urllib'

Expected behavior

no error reported

pylint --version output

Using config file .pylintrc
pylint 1.9.5,
astroid 1.6.5
Python 2.7.16 (default, Jul 12 2019, 01:42:49)
[GCC 6.3.0 20170516]

ref: #769

@PCManticore PCManticore changed the title conditional import against six.PY2 still emit error conditional import against six.PY2 emits error Apr 23, 2020
@PCManticore
Copy link
Contributor

Thanks for the report. The original #769 issue was related to fallback imports, but we should support six as well.

@LexiconCode
Copy link

LexiconCode commented Nov 25, 2020

I ran into this issue troubleshooting Linting in Github Actions. At 1st I thought it was an issue with the Python install tk dependency. However I narrowed it down to six and pylint

Test case 1
Results as follows:

  • python 2 windows (2.7.18) Linting Fail
    pylint-1.9.5
    E: 7, 4: Unable to import 'tkinter' (import-error)

  • python 3 windows (3.8.6) Success Linting
    pylint 2.6.0

  • python 3 linux (3.8.6) Linting Fail
    pylint 2.6.0
    E: 7, 4: Unable to import 'tkinter' (import-error)

  • python 3 MacOs (3.8.6) Success Linting
    pylint 2.6.0

tk_test.py

import sys, six
print(sys.version)

if six.PY2:
    import Tkinter as tk
else:
    import tkinter as tk

print(tk.TkVersion) # succeeds in all platforms to print version number

Test Case 2
Results as follows:

  • Success on all platforms
import sys
print(sys.version)

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

print(tk.TkVersion)

Github Actions Configuration for both tests
https://0bin.net/paste/sGbbX84r#vxpe73nMg6-YHd+Y+Z+hqCl8YRh9a8pmzgMK01PfWeF

    name: Python Pylint Test
     
    on: [push]
     
    jobs:
      python-windows-2-7:
            name: python 2 windows
            runs-on: windows-latest
            strategy:
              matrix:
                python-version: [2.7.x]
            steps:
              - uses: actions/checkout@v2
              - name: Set up Python
                uses: actions/setup-python@v2
                with:
                  python-version: ${{ matrix.python-version }}
              - name: Install dependencies
                run: |
                  python -m pip install --upgrade pip
                  pip install --upgrade setuptools
                  pip install six 
                  pip install pylint 
              - name: Run tk_test.py
                run: |
                  python tk_test.py
              - name: Lint with pylint
                run: |
                  pylint -E tk_test.py
      python-windows-3-8-x:
            name: python 3 windows
            runs-on: windows-latest
            strategy:
              matrix:
                python-version: [3.8.x]
            steps:
              - uses: actions/checkout@v2
              - name: Set up Python
                uses: actions/setup-python@v2
                with:
                  python-version: ${{ matrix.python-version }}
              - name: Install dependencies
                run: |
                  python -m pip install --upgrade pip
                  pip install --upgrade setuptools
                  pip install six
                  pip install pylint 
              - name: Lint with pylint
                run: |
                  pylint -E tk_test.py
      python-linux-3-8-x:
            name: python 3 linux
            runs-on: ubuntu-20.04
            strategy:
              matrix:
                python-version: [3.8.x]
            steps:
              - uses: actions/checkout@v2
              - name: Set up Python
                uses: actions/setup-python@v2
                with:
                  python-version: ${{ matrix.python-version }}
              - name: Install dependencies
                run: |
                  python -m pip install --upgrade pip
                  pip install --upgrade setuptools
                  pip install six
                  pip install pylint 
              - name: Run tk_test.py
                run: |
                  python tk_test.py
              - name: Lint with pylint
                run: |
                  pylint -E tk_test.py
      python-macos-3-8-x:
            name: python 3 MacOs
            runs-on: macos-latest
            strategy:
              matrix:
                python-version: [3.8.x]
            steps:
              - uses: actions/checkout@v2
              - name: Set up Python
                uses: actions/setup-python@v2
                with:
                  python-version: ${{ matrix.python-version }}
              - name: Install dependencies
                run: |
                  python -m pip install --upgrade pip
                  pip install --upgrade setuptools
                  pip install six
                  pip install pylint 
              - name: Run tk_test.py
                run: |
                  python tk_test.py
              - name: Lint with pylint
                run: |
                  pylint -E tk_test.py

@Pierre-Sassoulas
Copy link
Member

Closing as it's related to six / python 3 porting so unlikely to get attention, and also because the generic issue seems related to control-flow which has dozen of open issues already.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
4 participants