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

Apply repo-review suggestions #1519

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

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Aug 24, 2024

  • I have added a news fragment under changelog.d/ (if the patch affects the end users)

Summary of changes

More verbose MyPy and resulting fixes.

Test plan

Pass CI.

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the repo-review branch 4 times, most recently from b4cf32f to af783b0 Compare August 24, 2024 16:25
@@ -38,7 +38,7 @@ def environment(value: str) -> ExitCode:
"PIPX_HOME_ALLOW_SPACE": str(paths.ctx.allow_spaces_in_home_path).lower(),
}
if value is None:
print("Environment variables (set by user):")
print("Environment variables (set by user):") # type: ignore[unreachable]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

value is not Optional, so in theory it cannot be None.

Do we still want to defend against an actual None?

@@ -32,7 +32,7 @@ def inject_dep(
) -> bool:
logger.debug("Injecting package %s", package_spec)

if not venv_dir.exists() or not next(venv_dir.iterdir()):
if not venv_dir.exists() or next(venv_dir.iterdir(), None) is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

venv_dir.iterdir() yields Path which does not implement __bool__ or __len__ so it will always be true in boolean context. We might want to defend against StopIteration exceptions raised by next().

@@ -125,7 +125,7 @@ def uninject(
) -> ExitCode:
"""Returns pipx exit code"""

if not venv_dir.exists() or not next(venv_dir.iterdir()):
if not venv_dir.exists() or next(venv_dir.iterdir(), None) is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

venv_dir.iterdir() yields Path which does not implement __bool__ or __len__ so it will always be true in boolean context. We might want to defend against StopIteration exceptions raised by next().

@@ -198,11 +198,11 @@ def run(
# we can't parse this as a package
package_name = app

content = None if spec is not None else maybe_script_content(app, is_path)
content = None if spec is not None else maybe_script_content(app, is_path) # type: ignore[redundant-expr]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

spec is not Optional, so in theory it cannot be None.

Do we still want to defend against an actual None?

if content is not None:
run_script(content, app_args, python, pip_args, venv_args, verbose, use_cache)
else:
package_or_url = spec if spec is not None else app
package_or_url = spec if spec is not None else app # type: ignore[redundant-expr]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same.

@@ -409,7 +409,7 @@ def run_pipx_command(args: argparse.Namespace, subparsers: Dict[str, argparse.Ar
python_flag_passed=python_flag_passed,
)
elif args.command == "runpip":
if not venv_dir:
if not venv_dir: # type: ignore[truthy-bool]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory, venv_dir cannot be None.

Do we still want to defend against an actual None?

@@ -114,7 +114,7 @@ def upgrade(self, *, pip_args: List[str], verbose: bool = False, raises: bool =
return

if pip_args is None:
pip_args = []
pip_args = [] # type: ignore[unreachable]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pip_args is not Optional, so in theory it cannot be None.

Do we still want to defend against an actual None?

@DimitriPapadopoulos DimitriPapadopoulos marked this pull request as ready for review August 24, 2024 18:46
RF003: src directory doesn't need to be specified anymore (0.6+)

Ruff now (0.6+) looks in the src directory by default. The src
setting doesn't need to be specified if it's just set to `["src"]`.
MY103: MyPy warn unreachable

Must have `warn_unreachable` (true/false) to pass this check. There are
occasionally false positives (often due to platform or Python version
static checks), so it's okay to set it to false if you need to. But try
it first - it can catch real bugs too.

MY104: MyPy enables ignore-without-code

Must have `"ignore-without-code"` in `enable_error_code = [...]`. This
will force all skips in your project to include the error code, which
makes them more readable, and avoids skipping something unintended.

MY105: MyPy enables redundant-expr

Must have `"redundant-expr"` in `enable_error_code = [...]`. This helps
catch useless lines of code, like checking the same condition twice.

MY106: MyPy enables truthy-bool

Must have `"truthy-bool"` in `enable_error_code = []`. This catches
mistakes in using a value as truthy if it cannot be falsy.
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.

1 participant