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

Infer state defaults from typing #10

Open
JamesArruda opened this issue Dec 11, 2024 · 2 comments
Open

Infer state defaults from typing #10

JamesArruda opened this issue Dec 11, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request future Check back in the future

Comments

@JamesArruda
Copy link
Collaborator

Typing ResourceState and setting the default are most commonly going to be duplicated. This is similar for State values and the valid_type argument.

This looks more complicated:

class CashRegister(UP.Actor):
    waiting_customers = UP.ResourceState[simpy.Store](default=simpy.Store)
   number_served = UP.State[int](default=0, valid_types=int)

than this:

class CashRegister(UP.Actor):
    waiting_customers = UP.ResourceState[simpy.Store]()
    number_served = UP.State[int](default=0)

Any changes made here would have to allow for union types that would still require a single default value.

@JamesArruda JamesArruda added the enhancement New feature or request label Dec 11, 2024
@JamesArruda JamesArruda self-assigned this Dec 11, 2024
@JamesArruda
Copy link
Collaborator Author

There's also a frustrating problem where:

class Cashier(UP.Actor):
     a_queue = UP.ResourceState[UP.SelfMonitoringStore]()
   
    def q_help(self) -> None:
        self.a_queue._record() # <- type hinter fails

The type hinting will think a_queue is of type Store or Container and complain about using _record() (which you may want to do if you're doing things to items directly).

@JamesArruda
Copy link
Collaborator Author

This may have to wait until PEP 718.

@JamesArruda JamesArruda added the future Check back in the future label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request future Check back in the future
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant