Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

property setters in k2.Fsa never get called #848

Closed
csukuangfj opened this issue Oct 21, 2021 · 1 comment
Closed

property setters in k2.Fsa never get called #848

csukuangfj opened this issue Oct 21, 2021 · 1 comment

Comments

@csukuangfj
Copy link
Collaborator

See the setter for labels below

k2/k2/python/k2/fsa.py

Lines 440 to 441 in 2537a3f

@labels.setter
def labels(self, values) -> None:

Because of the presence of the following function

def __setattr__(self, name: str, value: Any) -> None:

fsa.labels = xxx is always dispatched to fsa.__setattr__, so we can actually remove @labels.setter since it is never called.


A minimal example to illustrate the issue is given below

#!/usr/bin/env python3


class Foo:
    @property
    def bar(self):
        return 10

    @bar.setter
    def bar(self, value):
        print("set bar")

    def __setattr__(self, name, value):
        print(f"set attr: {name}")


f = Foo()
print("f.bar", f.bar)
f.bar = 100

The output is

f.bar 10
set attr: bar
@csukuangfj csukuangfj changed the title property setters in k2 never get called property setters in k2.Fsa never get called Oct 21, 2021
@csukuangfj
Copy link
Collaborator Author

Closed via #850

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant