Pylance: I am the best Python language server for VSCode!

Also Pylance: No, you can't use a List[str] as an Iterable[str], that's a no-no!

Do I not understand how Python types work? 😂

@NickKaramoff Umm, pylance is correct. Python lists are iterable, but they are not iterators.

@bpepple I know; there is nothing about iterators in my issue :)

Pylance complains about me putting __path__ (a List of str) as the first attribute in pkgutils.extend_path (which is typed as Iterable of str) 🤷

@NickKaramoff Ah, wasn't clear from your toot.

I vaguely remember something about __path__ being a list of str in python2 but the behavior change in python3. Probably would need to look at the PEP for Namespace packages for the specifics.

@bpepple I just realized what the error was.

It's not about using list[str] as Iterable[str] in extend_path; it's about reassigning the result back to __path__

extend_path returns Iterable[str], but Pylance thinks that __path__ is a List[str] — and you can't assign an Iterable to a List

However, one should be able to do that, since Python docs say "__path__ must be an iterable of strings"; not necessarily a list :)

Sign in to participate in the conversation

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.