♻️ Refactor the handling of shellingham#1347
Conversation
…b.com/nathanjmcdougall/typer into config/lazy-load-shellingham-via-ruff
…b.com/nathanjmcdougall/typer into config/lazy-load-shellingham-via-ruff
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
Fair question, I think probably I'm being loose with my terminology and write-ups. Since The next thing the PR does is introduce a unified method A side effect of having a What about the lazy loading? To answer your question regarding performance, I don't think performance is a concern here. However, I think it's the least confusing approach in light of the above, and it now only occurs in a single file (except the test suite, perhaps we should disable the lazy-loading Ruff rules in the test suite since it adds little value there). |
shellingham
svlandeg
left a comment
There was a problem hiding this comment.
Thanks for the PR @nathanjmcdougall!
I like the idea of having a HAS_SHELLINGHAM var declared in core.py just once, and importing it from there. And using find_spec instead of the try import setup we had before.
The new _get_shell_name also looks good and simplifies various other checks in the code base.
I also agree with putting shellingham.detect_shell under import ban to ensure we always use the new _get_shell_name and avoid re-raising the ShellDetectionFailure.
The only thing I don't necessarily agree with, is enforcing the "lazy loading" of shellingham in the pyproject.toml. It feels a bit unnecessarily rigid, especially if we have to rewrite the test files because of it. shellingham is specified in our requirements-tests.txt and I personally find the code less clean if the imports aren't all at the top - so I'm not in favour of those edits in the 3 test modules.
Alternatively, if we really do want to enforce using shellingham only from within functions, it would be nice if we could exclude the test suite.
… specificcally `shellingham.detect_shell`
📝 Docs previewLast commit 9c36709 at: https://b883b622.typertiangolo.pages.dev |
…b.com/nathanjmcdougall/typer into config/lazy-load-shellingham-via-ruff
…b.com/nathanjmcdougall/typer into config/lazy-load-shellingham-via-ruff
|
Alright, that makes sense to me. I've removed the lazy-loading aspects from the PR. |
svlandeg
left a comment
There was a problem hiding this comment.
This looks good to me - I'll defer to Tiangolo for a final review though.
See #1297 for motivation.
There's a few places where a conditional check can be simplified but the logic is somewhat subtle. Basically the key thing to bear in mind is that the new
_get_shell_namemethod handles the case whereHAS_SHELLINGHAMis false by returning None.There were a couple calls to
shellingham.detect_shellthat potentially could have raisedShellDetectionFailure, so I've put this under API ban in favour of the_get_shell_namemethod.