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

Parameter defaults: which behaviour? Be precise #20

Open
eliegoudout opened this issue Jan 14, 2025 · 1 comment
Open

Parameter defaults: which behaviour? Be precise #20

eliegoudout opened this issue Jan 14, 2025 · 1 comment

Comments

@eliegoudout
Copy link
Owner

Currently, values are looked-up in instance dict and then in class MRO. Furthermore, default values are inferred at class creation from the latest class defining it as parameter and are immutable. For example:

# Currently
from paramclasses import IMPL, MISSING, ParamClass


class A(ParamClass):  # Defines "x" as one of its parameters
    x: int

class B(A):           # Does not define "x" as a parameter
    x = 0

B.x = 1

assert getattr(B, IMPL).default["x"] is MISSING  # Passes
B()                                              # B(x=1)

A.x = 2                                          # Doesn't affect default
assert getattr(A, IMPL).default["x"] is MISSING  # Passes
assert getattr(B, IMPL).default["x"] is MISSING  # Passes
  1. Is it ok to bypass classes not defining "x" as a parameter (e.g. B)?
  2. Shouldn't we reflect the A.x = 2 change in defaults? I think we should.

For 2., use a (param, owner) approach, similar to protected attributes.

@eliegoudout
Copy link
Owner Author

On the other hand, it's kind of weird to consider B().x == 1 as a non-default value, no?

@eliegoudout eliegoudout changed the title Parameter values: which behaviour? Be precise Parameter defaults: which behaviour? Be precise Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant