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

Clean-up: Avoid constructing Contexts with args[0], db, args[1], … #14

Open
rmoehn opened this issue Jul 3, 2018 · 2 comments
Open

Comments

@rmoehn
Copy link
Contributor

rmoehn commented Jul 3, 2018

There are several places in the code where a Context is constructed from datastore contents like this:

        all_successors = [Context(args[0], db, args[1], parent=args[2])
                for args in answer_successors + workspace_successors]

Replace these with something more readable.

This includes the args[0] in the procedure _can_advance_promise in context.py.

@rmoehn rmoehn changed the title Clean-up: Avoid constructing Contexts with args[0], db, args[1], … Clean-up: Avoid constructing Contexts with args[0], db, args[1], … Jul 3, 2018
@rmoehn
Copy link
Contributor Author

rmoehn commented Jul 11, 2018

The same goes for hypertext.Subquestion. Make it a namedtuple or a Python 3.7 dataclass.

rmoehn added a commit to rmoehn/patchwork that referenced this issue Sep 21, 2018
Something like

    Context(args[0], db, args[1], parent=args[2])

occurred in several places in the code. Since I might do more saving and
restoring of contexts, introduce a simple attrs container class to make
this prettier.

I considered three alternatives.

- Dictionaries wouldn't match the style of the rest of the code.

- Python 3.7 dataclasses have fewer features than attrs classes and the
  API quality is the same.

- A hand-written class would be three times as long.

Addresses issue oughtinc#14.
@rmoehn
Copy link
Contributor Author

rmoehn commented Sep 21, 2018

The construction of Workspaces is similarly repetitive.

rmoehn added a commit to rmoehn/patchwork that referenced this issue Sep 25, 2018
Something like

    Context(args[0], db, args[1], parent=args[2])

occurred in several places in the code. Since I might do more saving and
restoring of contexts, introduce a simple attrs container class to make
this prettier.

I considered three alternatives.

- Dictionaries wouldn't match the style of the rest of the code.

- Python 3.7 dataclasses have fewer features than attrs classes and the
  API quality is the same.

- A hand-written class would be three times as long.

Addresses issue oughtinc#14.
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