Skip to content

Consider adding __enter__ and __exit__ magic methods #177

@ghost

Description

Why is there no __enter__ and __exit__ magic methods in Zeroconf class?
Adding them would allow using it with with statement, simplifying it's usage.

This code from example:

zeroconf = Zeroconf()
try:
    print(zeroconf.get_service_info(TYPE, NAME + '.' + TYPE))
finally:
    zeroconf.close()

would become just:

with Zeroconf() as zeroconf:
    print(zeroconf.get_service_info(TYPE, NAME + '.' + TYPE))

P.S. Yes, i know that i can do that with contextlib.closing()

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