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

docker.legacy_build(pull="never") is treated as pull=True #466

Open
LewisGaul opened this issue Aug 11, 2023 · 5 comments
Open

docker.legacy_build(pull="never") is treated as pull=True #466

LewisGaul opened this issue Aug 11, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@LewisGaul
Copy link
Collaborator

It seems that APIs that only accept booleans will be interpreted as a boolean value even if another type is given. This is particularly confusing in the case of docker.legacy_build(pull: bool), which is subtly different to docker.run(pull: str). Would it be worth doing some arg type validation, at least in the Command.add_flag() method?

@gabrieldemarmiesse
Copy link
Owner

gabrieldemarmiesse commented Aug 12, 2023

Yes I think that would be helpful. I would be happy to get such a PR :)

EDIT: Maybe we should consider using beartype for this. That would avoid some complexity in our arguments. Maybe we should decorate our public api with this?

@LewisGaul
Copy link
Collaborator Author

Maybe we should consider using beartype for this. That would avoid some complexity in our arguments. Maybe we should decorate our public api with this?

That sounds like an interesting idea, I hadn't come across beartype before - what enigmatic docs!

@gabrieldemarmiesse gabrieldemarmiesse added the enhancement New feature or request label Aug 14, 2023
@kashyab12
Copy link
Contributor

EDIT: Maybe we should consider using beartype for this. That would avoid some complexity in our arguments. Maybe we should decorate our public api with this?

@gabrieldemarmiesse would the following suffice?

from beartype import beartype
...
    @beartype
    def add_flag(self, name: str, value: bool):
        if value:
            self.append(name)

I asserted that beartype catches these issues at runtime, so this should solve str types being passed. Moreover, the if value check can also removed as a result of this.

@gabrieldemarmiesse
Copy link
Owner

The issue with adding the beartype decorator used in non-public APIs is that the error messages won't be clean for the users. The error message will talk about a type mismatch in an internal function and it won't be obvious what caused this. I tend to think that decorating public apis functions with beartype would make error messages clearer from a user perspective.

@kashyab12
Copy link
Contributor

That makes lots of sense, thanks for the explanation! I'm going to read more beartype docs before trying to work a fix. Appreciate the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants