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

Fixes support for classmethod when defining a configclass #901

Merged
merged 4 commits into from
Aug 29, 2024

Conversation

Mayankm96
Copy link
Contributor

@Mayankm96 Mayankm96 commented Aug 29, 2024

Description

Previously, the configclass instance did not properly parse classmethods. For instance, the following would fail:

from __future__ import annotations

"""Launch Isaac Sim Simulator first."""

from omni.isaac.lab.app import AppLauncher

# launch omniverse app
app_launcher = AppLauncher(headless=True)

"""Rest everything follows."""

from omni.isaac.lab.utils.configclass import configclass


@configclass
class DummyClass:

    a: int = 5

    def instance_method(self):
        print("Value of a: ", self.a)

    @classmethod
    def class_method(cls, value: int) -> DummyClass:
        return cls(a=value)


cfg = DummyClass()

# check all methods are callable
cfg.instance_method()
new_cfg1 = cfg.class_method(20)

# create the same config instance using class method
new_cfg2 = DummyClass.class_method(20)

This MR fixes the checks to make sure class-methods remain bound to the class and do not become instance variables.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@Mayankm96 Mayankm96 self-assigned this Aug 29, 2024
@Mayankm96 Mayankm96 added the bug Something isn't working label Aug 29, 2024
@Mayankm96 Mayankm96 marked this pull request as ready for review August 29, 2024 14:57
Copy link
Collaborator

@jsmith-bdai jsmith-bdai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I would just triple check that there are no other instances of this calling pattern

@Mayankm96 Mayankm96 merged commit cdfa954 into main Aug 29, 2024
2 of 3 checks passed
@Mayankm96 Mayankm96 deleted the fix/class-method-configclass branch August 29, 2024 15:06
@Mayankm96
Copy link
Contributor Author

Thank you for the quick review! I checked and there are no other occurrences :)

iamdrfly pushed a commit to iamdrfly/IsaacLab that referenced this pull request Nov 21, 2024
…m#901)

# Description

Previously, the configclass instance did not properly parse
classmethods. For instance, the following would fail:

```python
from __future__ import annotations

"""Launch Isaac Sim Simulator first."""

from omni.isaac.lab.app import AppLauncher

# launch omniverse app
app_launcher = AppLauncher(headless=True)

"""Rest everything follows."""

from omni.isaac.lab.utils.configclass import configclass


@configclass
class DummyClass:

    a: int = 5

    def instance_method(self):
        print("Value of a: ", self.a)

    @classmethod
    def class_method(cls, value: int) -> DummyClass:
        return cls(a=value)


cfg = DummyClass()

# check all methods are callable
cfg.instance_method()
new_cfg1 = cfg.class_method(20)

# create the same config instance using class method
new_cfg2 = DummyClass.class_method(20)
```

This MR fixes the checks to make sure class-methods remain bound to the
class and do not become instance variables.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants