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

Update GetEdk2RelativePathFromAbsolutePath and GetAbsolutePathOnThisSystemFromEdk2RelativePath path input type hinting #672

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

antklein
Copy link
Contributor

@antklein antklein commented Nov 21, 2024

For GetEdk2RelativePathFromAbsolutePath change the type hinting of abspath from Tuple of strings to just str.
For GetAbsolutePathOnThisSystemFromEdk2RelativePath change the type hinting of relpath from Tuple of strings to just str.

This fixes the error messages from Pylint and Ruff about incompatible input types when using the functions as suggested. When attempting to pass a Tuple of strings to the functions, the functions would raise an error.

File "...\site-packages\edk2toollib\uefi\edk2\path_utilities.py", line 224, in GetAbsolutePathOnThisSystemFromEdk2RelativePath
    relpath = Path(*[part.replace("\\", "/") for part in relpath])
                     ^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'replace'

On the opposite, this is the PyLance error that's shown when using the function with multiple literal string inputs.

Argument of type "Literal['Test']" cannot be assigned to parameter "relpath" of type "Tuple[str, ...]" in function "GetAbsolutePathOnThisSystemFromEdk2RelativePath"
  "Literal['Test']" is not assignable to "Tuple[str, ...]"Pylance[reportArgumentType](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportArgumentType)

…ystemFromEdk2RelativePath path input type hinting
@Javagedes
Copy link
Contributor

@antklein What I was trying to annotate with this particular type hint was that you can do things like GetAbsolutePathOnThisSystemFromEdk2RelativePath("path", "to", "my", "file"). Is the current type hinting you are changing it to reflect that?

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.43%. Comparing base (ce85203) to head (131a60f).
Report is 123 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #672      +/-   ##
==========================================
- Coverage   81.43%   81.43%   -0.01%     
==========================================
  Files          56       45      -11     
  Lines        7514     7492      -22     
==========================================
- Hits         6119     6101      -18     
+ Misses       1395     1391       -4     

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


🚨 Try these New Features:

@antklein
Copy link
Contributor Author

@antklein What I was trying to annotate with this particular type hint was that you can do things like GetAbsolutePathOnThisSystemFromEdk2RelativePath("path", "to", "my", "file"). Is the current type hinting you are changing it to reflect that?

Yes, my understanding is that the asterisk handles the fact that the path input can be either be a single or multiple strings, and the type hinting only needs to specify the type of a single input.
https://stackoverflow.com/questions/37031928/type-annotations-for-args-and-kwargs

@Javagedes
Copy link
Contributor

@antklein What I was trying to annotate with this particular type hint was that you can do things like GetAbsolutePathOnThisSystemFromEdk2RelativePath("path", "to", "my", "file"). Is the current type hinting you are changing it to reflect that?

Yes, my understanding is that the asterisk handles the fact that the path input can be either be a single or multiple strings, and the type hinting only needs to specify the type of a single input. https://stackoverflow.com/questions/37031928/type-annotations-for-args-and-kwargs

Great. Thanks for verifying that for me :)

@Javagedes Javagedes added this to the v0.22.3 milestone Nov 21, 2024
@Javagedes Javagedes added the enhancement New feature or request label Nov 21, 2024
@Javagedes Javagedes merged commit 049e96b into tianocore:master Nov 21, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants