Skip to content

TypeError: unsupported operand type(s) for //: 'slice' and 'int' when slicing search results #180

@gbmerrall

Description

@gbmerrall

Version: python3-discogs-client 2.8
Python Version: 3.x (Reproduced on 3.10 and 3.12)

Attempting to slice a search results object (specifically a PaginatedList or MixedPaginatedList) using standard Python slicing notation (e.g., results[:10]) results in a TypeError. Perhaps a regression or an oversight in how the getitem method handles slice objects versus integer indices when calculating page offsets?

import discogs_client

# Initialize client
client = discogs_client.Client('YourUserAgent/0.1', user_token='YOUR_TOKEN')

# Perform a search
results = client.search('van morrison astral weeks', type='release')

# Attempt to slice the results
first_ten = results[:10]

# Trigger the error by iterating or accessing the slice
for item in first_ten:
  print(item.id)

Result: TypeError: unsupported operand type(s) for //: 'slice' and 'int'

Workaround

from itertools import islice
results = client.search('query', type='release')
limited_results = list(islice(results, 10))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions