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

"Type[arg[slice]]" is not iterable #59

Closed
htarnacki opened this issue Jul 6, 2020 · 2 comments
Closed

"Type[arg[slice]]" is not iterable #59

htarnacki opened this issue Jul 6, 2020 · 2 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@htarnacki
Copy link

hi,

following code:

class arg:

    def __getitem__(self, idx: Union[int, slice]) -> Any:
        return sys.argv[idx]

    def __len__(self) -> int:
        return len(sys.argv)

    def __call__(self, idx: int) -> Any:
        if idx == -1:
            arg, = sys.argv[-1:] or [None]
        else:
            arg, = sys.argv[idx:idx + 1] or [None]
        return arg


# make it singletone
arg = arg()

produces errors in pylance:
Zrzut_ekranu_2020-07-06-103935

Pylance do not see that class is instantiated. Changing class name to "Arg" solves the problems.

@erictraut
Copy link
Contributor

Thanks for reporting the issue.

Here's what's happening here. When you declare a class called arg, you're telling the type checker that the type of the symbol arg is a class. You're later trying to assign that same symbol a value that is not a class, so it's a type violation. The type checker would normally report this as an error, but by default Pylance has typeCheckingMode set to 'off', so that error is suppressed. Because it's suppressed, subsequent errors based on this type assumption don't make sense.

I think the correct fix here is to allow assignments to override the declared type of a symbol if typeCheckingMode is 'off'. In your case, it would allow the arg symbol to take on the type of an instance even though it is declared as having a class type above.

This change will be in an upcoming version of Pylance.

@erictraut erictraut added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Jul 6, 2020
@jakebailey
Copy link
Member

This issue has been fixed in version 2020.7.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202070-9-july-2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants