Skip to content

For unions, handle string types last#209

Open
brentyi wants to merge 493 commits into
mainfrom
brent/str_in_union_tweak
Open

For unions, handle string types last#209
brentyi wants to merge 493 commits into
mainfrom
brent/str_in_union_tweak

Conversation

@brentyi
Copy link
Copy Markdown
Owner

@brentyi brentyi commented Dec 4, 2024

Examples:

  • For arg: Optional[str] and arg: str | None, --arg None will create a None object instead of a string.
    • This was already happening.
  • For arg: str | bool, --arg True will create a boolean instead of a string.
    • This is new.
  • For arg: str | int, integers will be created when possible instead of strings.
    • This is new.

Questions raised:

  • Should we also handle arg: tuple[str, ...] | int?
  • How about Optional[list[str]]?

brentyi and others added 30 commits November 28, 2022 23:23
It does not appear to be used for anything other than tests
* Support os.PathLike

* Fix missing import, add os.PathLike helptext test

* Un-rename file to avoid merge conflict
…__ (#38)

* Add support for PathLike classes & objects with __new__ but no __init__

* Update _instantiators.py

* Formatting

---------

Co-authored-by: Brent Yi <yibrenth@gmail.com>
* Start subcommand matching refactor

* Improve test coverage

* Format

* Patch for 3.7
Previously, if a `str` type argument's default value contains `%`, the
`--help` action fails.  Reproducible example:

```bash
$ cat >percent-char.py <<EOF
import tyro
from dataclasses import dataclass

@DataClass
class A:
    name: str = "%"

def main(args: A):
    print(args.name)

if __name__ == "__main__":
    tyro.cli(main)
EOF

$ python percent-char.py --help
[...truncated...]
  File "/.../lib/python3.9/argparse.py", line 630, in _expand_help
    return self._get_help_string(action) % params
ValueError: unsupported format character ')' (0x29) at index 29
```

This commit fixes this and updates the test for default help text to
cover this case.

Signed-off-by: Gaoyang Zhang <gy@blurgy.xyz>
* Improvements for numeric tower edge cases

* Fix test for Python <3.10
* Docs pass, primitive rule priority

* Fix default primitive rules

* tests

* sync docs

* union fix
* Switch to hatchling

* bump years
* Docs / examples rework

* nits

* Refinements

* ruff

* ignore mypy errors for docs update script
* Helptext, docs fixes

* refine
* Support Python 3.13

* Update pyproject.toml

* Test annotated struct narrowing

* ruff

* mypy

* Add narrow_subtype test

* ruff
* Constructors + examples refinements

* formatting/regenerate docs

* Move test

* ruff

* Python 3.7

* ruff
* Apply `use_underscores` to subcommand names for `tyro.extras.SubcommandApp`

* pydantic NewType fix
…oved error messages (#204)

* Improve mismatched type for StrEnum

* Overhaul subcommand matching

* Additional subcommand matching tests

* Min 3.11 for StrEnum tests

* fix test ignore

* Test nits

* typeguard compatibility

* Add minimum typeguard version

* fix typeguard errors

* typeguard refactor, more subcommand matching tests

* Add 3.13 to CI (fixes #206)

* Add pydantic version exclude, waiting for patch
Related: pydantic/pydantic#10912, pydantic/pydantic#10909

* Improve type warnings + errors

* Generic subcommand example, docs updates

* Remove unused

* `build` => `pytest`, closes #206

* mypy
Signed-off-by: Brent Yi <yibrenth@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 4, 2024

Codecov Report

❌ Patch coverage is 99.76371% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.78%. Comparing base (b6c0cd6) to head (37dc485).
⚠️ Report is 718 commits behind head on main.

Files with missing lines Patch % Lines
src/tyro/_docstrings.py 93.61% 3 Missing ⚠️
src/tyro/_argparse_formatter.py 99.70% 1 Missing ⚠️
src/tyro/_fields.py 99.31% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #209      +/-   ##
==========================================
+ Coverage   99.16%   99.78%   +0.62%     
==========================================
  Files          19       28       +9     
  Lines        1552     2302     +750     
==========================================
+ Hits         1539     2297     +758     
+ Misses         13        5       -8     
Flag Coverage Δ
unittests 99.78% <99.76%> (+0.62%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.