Skip to content

Files

Latest commit

 

History

History
32 lines (20 loc) · 650 Bytes

unsubscriptable-object.md

File metadata and controls

32 lines (20 loc) · 650 Bytes

Pattern: Unsubscriptable object

Issue: -

Description

Emitted when a subscripted value doesn't support subscription (i.e. doesn't define __getitem__ method).

Example of incorrect code:

class NonSubscriptable(object):
    pass
    
NonSubscriptable()[0]  # [unsubscriptable-object]
NonSubscriptable[0]  # [unsubscriptable-object]

Example of correct code:

class Subscriptable(object):
    def __getitem__(self, key):
        return key + key

Subscriptable()[0]

Further Reading