Skip to content

Python generator-based impl #24

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

Closed
wants to merge 2 commits into from
Closed

Conversation

Starlight220
Copy link
Contributor

No description provided.

self.value = value


class CommandTestBase(unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you're using python unittest library? pytest is much less verbose and is preferred (and is what our other tests use).

Copy link
Contributor Author

@Starlight220 Starlight220 Mar 6, 2023

Choose a reason for hiding this comment

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

Nope, this is what IntelliJ gave me and I didn't know better to change.

I'll change to use pytest.



class Command:
requirements: Set[Requirement] = {}
Copy link
Member

Choose a reason for hiding this comment

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

Should use instance variables, not class variables.

Copy link
Member

Choose a reason for hiding this comment

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

The types don't match in this statement either. The RHS is a dict.

from .requirement import Requirement, InterruptBehavior


class Command:
Copy link
Member

Choose a reason for hiding this comment

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

I see this has one abstract method.
I think this whole class should be a Protocol then.

@auscompgeek Thoughts on that? Protocol vs ABC?

Copy link
Member

Choose a reason for hiding this comment

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

Depends on when we want errors to be caught I guess. If we want errors when instantiating the class then an ABC is appropriate. Otherwise if we want duck typing then a Protocol will provide that.

If there's only one method, and no custom constructor, probably no huge advantage to an ABC?

setattr(self, "_composed", True)


def commandify(
Copy link
Member

Choose a reason for hiding this comment

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

If you really do want to shoehorn end into the coroutine version, you have have commandify return return a class that can be used as a decorator to specify end.

@commandify
def my_command():
	...

@my_command.end
def the_end_for_my_command():
	...

I'd rather omit end and only support it for class based commands

Copy link
Member

Choose a reason for hiding this comment

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

I think we could support end by throwing an exception into the coroutine

Copy link
Member

@TheTripleV TheTripleV Mar 7, 2023

Choose a reason for hiding this comment

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

Yeah I think that would be better. There could be a CommandInterrupted exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that would complicate user-side code.
Honestly, I kindof like the .end decorator idea.

Copy link
Member

Choose a reason for hiding this comment

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

Well I think ideally most users don't use end at all and this is just a workaround for the few that do. By making it an exception, you have access to the existing context of the coroutine.

@virtuald
Copy link
Member

virtuald commented Mar 6, 2023

Two more thoughts:

assert cond.getCondition()
assert not scheduler.isScheduled(cmd)
assert cond.get_condition()
assert not scheduler.is_scheduled(cmd)
Copy link
Member

Choose a reason for hiding this comment

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

If we were to provide a python implementation of commands, a primary goal would be to attempt to keep backwards compat with the current commands so that teams don't have to rewrite everything next year. Historically, we've used java camelcase conventions for function names, so we should stick to that.

Ideally, all of this year's tests (and any tests written for this effort that aren't coroutine related) should pass without modification on either the C++ codebase or the pure python implementation.

@auscompgeek
Copy link
Member

We wrote a HTML page that can convert java function definitions + comments to an appropriately typed python function definition + docstring

I actually preserved that functionality in sphinxify as well

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.

4 participants