Repository navigation
Fix all reportPrivateImportUsage in pyright for library users - #1551
GBeauregard wants to merge 1 commit into
Conversation
This commit adds TYPE_CHECKING guards to the __main__ sections of all files that imported/redefined part of their own API in this section. This hides the redefinition from type checkers as needed to avoid accidentally signalling the API as private.
|
I brought up the possibility of excluding |
Codecov Report
@@ Coverage Diff @@
## master #1551 +/- ##
==========================================
- Coverage 99.70% 99.70% -0.01%
==========================================
Files 71 71
Lines 6854 7091 +237
==========================================
+ Hits 6834 7070 +236
- Misses 20 21 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
I'm not overly keen on that workaround. The main sections are excluded from coverage, but I still like them to be typechecked. Could the individual lines be excluded in Pyright, rather than the entire block? |
My understanding is no since the error is happening downstream. I will double check for posterity and open a PR with such a change if it works. I believe you have 3 options that resolve the issue:
|
|
Thanks. I think I'll go with 2.
|
Type of changes
Checklist
Description
This PR adds
TYPE_CHECKINGguards to the__main__sections of all files that imported/redefined part of their own API in this section. This hides the redefinition from type checkers as needed to avoid accidentally signalling the API as private and causing pyright errors for everyone using rich as a library.Note there are many more
__main__sections in the library; it was only necessary to add the guard to files importing their own API.This PR resolves #1523
I didn't update CONTRIBUTORS since the change is minor, but if you have a policy of always updating it let me know and I'll add my name.