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

Union handles lists #308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

grahamannett
Copy link

@grahamannett grahamannett commented Mar 13, 2024

For #297

There might be a more elegant way to handle this but I think it would require redoing a lot more than this?

I also am not sure if this is the correct place to put this as there seemed like 2-3 other potential places and maybe more if i kept looking.

The if/else stuff is basically just trying to handle the equivalent of below (which probably makes more sense if there are more cases to worry about for UnionTypes):

  if any(utils.is_list(o) for o in utils.get_args(self.type)):
      # for: Union[list[int], list[str]] keep as list
      if all(utils.is_list(o) for o in utils.get_args(self.type)):
          return raw_parsed_value
      # for Union[str, list[str]] if single value, then dont keep as list
      elif len(raw_parsed_value) == 1:
          return raw_parsed_value[0]
  # are there other cases?

Copy link
Owner

@lebrice lebrice left a comment

Choose a reason for hiding this comment

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

Nice! Thanks @grahamannett ! :)

@grahamannett
Copy link
Author

Seems like the linter or pre-commit checks failed? Not sure if that was because of me, I didn't see any info on what to do and the default hooks/pre-commit stuff did not work for me but didn't spend too much time trying.

I can go back and try and fix the PR to see if that would be helpful and besides line length I am not sure what other things in the pre-commit might be different (I use black but probably should switch to ruff it seems, just had issues getting it to work as I wanted when I had looked into using it prior)

@lebrice
Copy link
Owner

lebrice commented Mar 19, 2024

Hey @grahamannett , yes its the pre-commit hooks which are failing.
Can you do

pip install pre-commit
pre-commit run --all-files

And commit the changes to the files you changed? That should fix it.

Thanks again!

@grahamannett
Copy link
Author

@lebrice just ran it and commit the file that changed related to what I PR'ed earlier but still says ruff-format is failing from my setup.

@lebrice
Copy link
Owner

lebrice commented Mar 19, 2024

@lebrice just ran it and commit the file that changed related to what I PR'ed earlier but still says ruff-format is failing from my setup.

Ok no prob I'll take a look tomorrow.
Thanks again!

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.

2 participants