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

ENH: Define instance attributes in __init__ method #133

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

jhlegarreta
Copy link
Collaborator

Define instance attributes in __init__ method.

Fixes:

Instance attribute _datashape defined outside __init__

and similar warnings.

Define instance attributes in `__init__` method.

Fixes:
```
Instance attribute _datashape defined outside __init__
```

and similar warnings.
@jhlegarreta jhlegarreta force-pushed the DefineInstanceAttributesInInit branch from aab425f to ae4a650 Compare March 21, 2024 13:05
@oesteban
Copy link
Member

I'm surprised - is this a problem despite them being listed in __slots__?

Happy to merge if this is not just the face of a deeper problem

@jhlegarreta
Copy link
Collaborator Author

Looks like it is still recommended to initialize the values in the __init__ method:
https://wiki.python.org/moin/UsingSlots

If the above ref is not enough, the below does not say they are a substitute for the __init__ initialization:
https://docs.python.org/3/reference/datamodel.html#object.__slots__

And pylint has a warning for this as well:
https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/attribute-defined-outside-init.html

Not sure whether there are other aspects that make the behavior to be different in some cases.

@oesteban oesteban merged commit dbe8719 into nipreps:main Mar 28, 2024
7 checks passed
@jhlegarreta jhlegarreta deleted the DefineInstanceAttributesInInit branch March 28, 2024 13:52
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

Successfully merging this pull request may close these issues.

2 participants