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

Declare class attributes outside of constructor #5

Open
LouisCarpentier42 opened this issue Dec 5, 2024 · 0 comments
Open

Declare class attributes outside of constructor #5

LouisCarpentier42 opened this issue Dec 5, 2024 · 0 comments

Comments

@LouisCarpentier42
Copy link
Collaborator

Currently, the properties of a class are defined within the constructor. Something like:

class Example:

    def __init__(self, parameter: type1):
        self.parameter: type = parameter
        self.learned_parameter_: type2 = None

In this case, we need to assign a value to the learned parameters (e.g., None), even though they do not exist yet. To deal with this more elegantly, the structure of the classes should be changed to:

class Example:
    parameter: type1
    learned_parameter_ : type2

    def __init__(self, parameter: type1):
        self.parameter = parameter
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