E466 ServiceBrowser handler argument overwrites zeroconf name · Issue #1092 · python-zeroconf/python-zeroconf · GitHub
[go: up one dir, main page]

Skip to content

ServiceBrowser handler argument overwrites zeroconf name #1092

@nils-werner

Description

@nils-werner

In the default pattern

import zeroconf

instance = zeroconf.Zeroconf()
browser = zeroconf.ServiceBrowser(
    instance,
    ['_osc._udp.local.'],
    handlers=[handler]
)

def handler(zeroconf, service_type, name, state_change):
    # I cannot use zeroconf.ServiceStateChange.Added here, because zeroconf is not the import but the argument
    pass

we have the problem that handler() is receiving a named argument zeroconf that overloads import zeroconf and that we cannot change. If I defined

def handler(zc, service_type, name, state_change):
    if state_change is zeroconf.ServiceStateChange.Added:
        print(name)

I would receive

TypeError: handler() got an unexpected keyword argument 'zeroconf'

To avoid it I would have to alias the import, which is a bit ugly:

import zeroconf as imported_zeroconf

def handler(zeroconf, service_type, name, state_change):
    if state_change is imported_zeroconf.ServiceStateChange.Added:
        print(name)

It would be nice if the arguments were to be passed in as positional arguments, or named differently, so that the names didn't clash.

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

      0