Skip to content

is_connected does not return a boolean value #2276

Closed
@yvan-the-barbarian

Description

@yvan-the-barbarian

Version: 4.3.4

Description

The is_connected property of the Connection class in redis.asyncio.connection.py returns either None, a StreamReader or a StreamWriter rather than a boolean value as would be expected.

While this will work for all cases where the "truthiness" is checked directly, it could cause weird issues in other cases.

Such as logging the connection state, for example:

# Prints: "Connection connected: <StreamWriter transport=<_ProactorSocketTransport fd=484 read=<_OverlappedFuture pending overlapped=<pending, 0x1666c1aa940> cb=[_ProactorReadPipeTransport._loop_reading()]>> reader=<StreamReader transport=<_ProactorSocketTransport fd=484 read=<_OverlappedFuture pending overlapped=<pending, 0x1666c1aa940> cb=[_ProactorReadPipeTransport._loop_reading()]>>>>"
print(f'Connection connected: {connection.is_connected}')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions