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

Record.like() should be a classmethod, not staticmethod. #283

Closed
kbob opened this issue Dec 20, 2019 · 3 comments
Closed

Record.like() should be a classmethod, not staticmethod. #283

kbob opened this issue Dec 20, 2019 · 3 comments
Labels

Comments

@kbob
Copy link

kbob commented Dec 20, 2019

The comments explicitly say that Record can be subclassed, so it would be good for Record.like to clone a Record subclass instead of downclassing to Record.

nMigen version: v.01.

@whitequark
Copy link
Contributor

That's not possible: if you override __init__ while subclassing Record and change the arguments in an incompatible way, then calling Record.like would fail.

@Fatsie
Copy link
Contributor

Fatsie commented Dec 21, 2019

BTW inside #266 this was discussed. There the following doc for like was suggested:

class Record(Value):
    @classmethod
    def like(cls, other, *, name=None, name_suffix=None, src_loc_at=0):
        """Return fresh object with same fields as other object

        Use Record.like(other) if one wants a Record object with same fields as other.
        Use other.__class__.like(other) if one wants an object of same class as other
        and with same fields."""

This way I think you can do what you want to do with current code.

@kbob
Copy link
Author

kbob commented Dec 21, 2019

Thanks for the workaround. That looks good.

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

No branches or pull requests

3 participants