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

Slicing Context raises KeyError in Python 3.6 #336

Open
BigRoy opened this issue Mar 22, 2018 · 1 comment
Open

Slicing Context raises KeyError in Python 3.6 #336

BigRoy opened this issue Mar 22, 2018 · 1 comment

Comments

@BigRoy
Copy link
Member

BigRoy commented Mar 22, 2018

Issue

In our plug-ins we've been doing context[:] to get a copy of the instances list from the context, though in Python 3.6 this is giving us the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\pyblish-base\pyblish\plugin.py", line 771, in __getitem__
    raise KeyError("%s not in list" % item)
KeyError: 'slice(None, None, None) not in list'

Confirmed and reproducable with:

import pyblish.api as api

c = api.Context()
print(c[:])

This works in Python 2.7 - but raises the error above in Python 3.6.

Workaround

It does however work when doing list(context) to get a copy of the list.

import pyblish.api as api

c = api.Context()
print(list(c))

Shouldn't the first one also work if it "should behave" like a regular list?

@BigRoy
Copy link
Member Author

BigRoy commented Mar 22, 2018

It seems to be coming from this line.

Refactoring it to:

        if isinstance(item, (int, slice)):

Allows the slicing to function as in a regular Python list in both Python 2.7 and Python 3.6.


Why it's working without this in Python 2.7 on the other hand makes me confused now.
It seems in Python 2.7 that with slicing it never enters the __getitem__ function. :)

More info:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant