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

Sequence index is not an int, slice, or instance with __index__ (with scipy.fft) #4083

Open
tschaub opened this issue Feb 11, 2021 · 4 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)

Comments

@tschaub
Copy link

tschaub commented Feb 11, 2021

Steps to reproduce

test.py

import numpy as np
from scipy import fft

def check(image_product):
    cross_correlation = fft.ifftn(image_product)
    maxima = np.unravel_index(np.argmax(np.abs(cross_correlation)), cross_correlation.shape)

    return cross_correlation[maxima]
pylint test.py --errors-only

Current behavior

************* Module test
test.py:6:68: E1101: Instance of 'tuple' has no 'shape' member (no-member)
test.py:8:11: E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)

Expected behavior

No errors.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0]

@PCManticore PCManticore added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) False Positive 🦟 A message is emitted but nothing is wrong with the code labels Feb 16, 2021
@cjmayo
Copy link

cjmayo commented Mar 2, 2021

Also with:

Steps to reproduce

type.py

types = ["test type"]


class Example:
    def __init__(self, type):
        self.type = types[type]

Current behavior

************* Module type
type.py:6:20: E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)

pylint --version output

pylint 2.7.2
astroid 2.5.1
Python 3.9.2
[GCC 9.3.0]

cjmayo added a commit to cjmayo/gnofract4d that referenced this issue Mar 3, 2021
Avoid false positives with 2.7.

2.7.0
https://github.com/fract4d/gnofract4d/runs/1955404235#step:9:15
E1101: Instance of 'OverloadList' has no 'ret' member (no-member)

2.7.2
E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)
pylint-dev/pylint#4083
cjmayo added a commit to cjmayo/gnofract4d that referenced this issue Mar 3, 2021
Avoid false positives with 2.7.

2.7.0
E1101: Instance of 'OverloadList' has no 'ret' member (no-member)
https://github.com/fract4d/gnofract4d/runs/1955404235#step:9:15

2.7.2
E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)
pylint-dev/pylint#4083
cjmayo added a commit to fract4d/gnofract4d that referenced this issue Mar 8, 2021
Avoid false positives with 2.7.

2.7.0
E1101: Instance of 'OverloadList' has no 'ret' member (no-member)
https://github.com/fract4d/gnofract4d/runs/1955404235#step:9:15

2.7.2
E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)
pylint-dev/pylint#4083
nelfin added a commit to nelfin/pylint that referenced this issue Apr 21, 2021
nelfin added a commit to nelfin/astroid that referenced this issue Apr 22, 2021
nelfin added a commit to nelfin/astroid that referenced this issue Apr 22, 2021
Ref pylint-dev/pylint#4083. Ref pylint-dev/pylint#4387. When used in a
nodes.Subscript, an existing inference_tip was set for Name nodes
matching called type. However, when this name was redefined this led to
false-positive typecheck errors in pylint such as invalid-sequence-index
(see pylint-dev/pylint#4083 and pylint-dev/pylint#4387)
nelfin added a commit to nelfin/astroid that referenced this issue Apr 22, 2021
Ref pylint-dev/pylint#4083. Ref pylint-dev/pylint#4387. When used in a
nodes.Subscript, an existing inference_tip was set for Name nodes
matching called type. However, when this name was redefined this led to
false-positive typecheck errors in pylint such as invalid-sequence-index
(see pylint-dev/pylint#4083 and pylint-dev/pylint#4387)
nelfin added a commit to nelfin/astroid that referenced this issue May 2, 2021
Ref pylint-dev/pylint#4083. Ref pylint-dev/pylint#4387. When used in a
nodes.Subscript, an existing inference_tip was set for Name nodes
matching called type. However, when this name was redefined this led to
false-positive typecheck errors in pylint such as invalid-sequence-index
due to the argument being inferred as builtins.type and inference_tip
preventing any further inference.
Pierre-Sassoulas pushed a commit to pylint-dev/astroid that referenced this issue May 2, 2021
Ref pylint-dev/pylint#4083. Ref pylint-dev/pylint#4387. When used in a
nodes.Subscript, an existing inference_tip was set for Name nodes
matching called type. However, when this name was redefined this led to
false-positive typecheck errors in pylint such as invalid-sequence-index
due to the argument being inferred as builtins.type and inference_tip
preventing any further inference.
@hippo91
Copy link
Contributor

hippo91 commented Aug 21, 2021

@cjmayo thanks for your message but it is not related to the original one. The issue noted by @tschaub is directly linked to the use of the numpy module.

@cjmayo
Copy link

cjmayo commented Aug 23, 2021

@cjmayo thanks for your message but it is not related to the original one. The issue noted by @tschaub is directly linked to the use of the numpy module.

Thanks, and mine appears to be fixed in:
pylint 2.9.3
astroid 2.6.2

@jrom99
Copy link

jrom99 commented Jan 7, 2022

Hello, this also happens in gspread, I tried to make a minimal reproducible example, but I'm not sure if I did it right.

Steps to reproduce

import os
from pathlib import Path

import gspread
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow


def get_creds(scopes: list[str], creds_file: Path, token_file: Path):
    creds = None
    if token_file.is_file():
        creds = Credentials.from_authorized_user_file(token_file, scopes)

    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        elif creds_file.is_file():
            flow = InstalledAppFlow.from_client_secrets_file(
                creds_file, scopes)
            creds = flow.run_local_server(port=0)
        else:
            raise FileNotFoundError(creds_file)
        with open(token_file, "w", encoding="utf-8") as token:
            token.write(creds.to_json())
    return creds


GMAIL_CREDS = Path(os.environ["GMAIL_CREDS"])  # client secrets file
GMAIL_TOKEN = Path("token.json")
SHEETS_ID = os.environ["GSPREADSHEET"]   # Google spreadsheet key 
credentials = get_creds(
    ['https://www.googleapis.com/auth/gmail.send'], GMAIL_CREDS, GMAIL_TOKEN)
service = gspread.authorize(credentials=credentials)


try:
    spreadsheet = service.open_by_key(SHEETS_ID)
except gspread.exceptions.APIError as err:
    if err.args[0]['status'] == 'PERMISSION_DENIED':  # offending line
        raise PermissionError(
            f"You don't have access to {SHEETS_ID!r}") from None
    raise
pylint test.py --errors-only

Current behaviour

************* Module test
test.py:40:7: E1126: Sequence index is not an int, slice, or instance with __index__ (invalid-sequence-index)

pylint --version output
pylint 2.12.2
astroid 2.9.2
Python 3.9.7 (default, Sep 10 2021, 14:59:43)
[GCC 11.2.0]

I tried the following:

error_data: dict[str, str] = err.args[0]
if error_data['status'] == 'PERMISSION_DENIED':
  ...

But pylint still sees error_data['status'] as an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade)
Projects
None yet
Development

No branches or pull requests

5 participants