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

[Minor Feature/Fix] Proper type annotations for tyro.conf.arg and tyro.conf.subcommand. #243

Closed
emcd opened this issue Jan 26, 2025 · 2 comments · Fixed by #249
Closed

Comments

@emcd
Copy link
Contributor

emcd commented Jan 26, 2025

Pyright does not believe that the types for tyro.conf.arg and tyro.conf.subcommand have been fully specified:

create.py:42:9 - error: Type of "arg" is partially unknown
    Type of "arg" is "Overload[(*, name: str | None = None, metavar: str | None = None, help: str | None = None, help_behavior_hint: str | ((str) -> str) | None = None, aliases: tuple[str, ...] | list[str] | None = None, prefix_name: bool | None = None, constructor: None = None, constructor_factory: (() -> (type | ((...) -> Unknown))) | None = None) -> Any, (*, name: str | None = None, metavar: str | None = None, help: str | None = None, help_behavior_hint: str | ((str) -> str) | None = None, aliases: tuple[str, ...] | list[str] | None = None, prefix_name: bool | None = None, constructor: type | ((...) -> Unknown) | None = None, constructor_factory: None = None) -> Any]" 
cli.py:48:13 - error: Type of "subcommand" is partially unknown
    Type of "subcommand" is "Overload[(name: str | None = None, *, default: Any = MISSING_NONPROP, description: str | None = None, prefix_name: bool = True, constructor: None = None, constructor_factory: (() -> (type | ((...) -> Unknown))) | None = None) -> Any, (name: str | None = None, *, default: Any = MISSING_NONPROP, description: str | None = None, prefix_name: bool = True, constructor: type | ((...) -> Unknown) | None = None, constructor_factory: None = None) -> Any]"
@brentyi
Copy link
Owner

brentyi commented Jan 28, 2025

Interesting, I haven't seen this error but I guess it's because we use Callable instead of Callable[..., Any]? Are you using strict mode when running pyright? I haven't been, but given the nature of this project perhaps I should.

@emcd
Copy link
Contributor Author

emcd commented Jan 28, 2025

No strict mode; I have found that to be... too strict. Here is my config:

[tool.pyright]
include = [ 'sources' ]
reportConstantRedefinition = true
reportInvalidTypeVarUse = true
reportMatchNotExhaustive = true
reportMissingImports = true
reportMissingTypeStubs = true
reportMissingTypeArgument = true
reportPossiblyUnboundVariable = false # Covered by other linters.
reportPrivateImportUsage = false      # Covered by other linters.
reportPrivateUsage = false            # Covered by other linters.
reportSelfClsParameterName = false    # Too opinionated.
reportUnknownArgumentType = true
reportUnknownLambdaType = true
reportUnknownMemberType = true
reportUnknownParameterType = true
reportUnknownVariableType = true
reportUnnecessaryCast = true
reportUnnecessaryComparison = true
reportUntypedBaseClass = true
reportUntypedClassDecorator = true
reportUntypedFunctionDecorator = true
reportUntypedNamedTuple = true
reportUnusedExpression = true
reportUnusedImport = false            # Covered by other linters.
reportUnusedVariable = false          # Covered by other linters.
#strict = [ 'sources' ]

This is with a Python 3.10 baseline. Recent version of Pyright:

$ hatch --env develop run python --version
Python 3.10.15
$ hatch --env develop run pip freeze | grep pyright
pyright==1.1.392.post0

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 a pull request may close this issue.

2 participants