microsoft / pyright

Static Type Checker for Python
Other
13.04k stars 1.39k forks source link

Changed the type of the `__doc__` attribute for a module to always be… #8397

Closed erictraut closed 1 month ago

erictraut commented 1 month ago

str | None. Previously, pyright changed its declared type to str if a docstring was present in the module, but this is incorrect because it's a writable value and can be set to None. This addresses #8388.

github-actions[bot] commented 1 month ago

Diff from mypy_primer, showing the effect of this PR on open source code:

pywin32 (https://github.com/mhammond/pywin32)
+   /tmp/mypy_primer/projects/pywin32/com/win32comext/adsi/demos/scp.py:397:19 - error: Operator "+" not supported for "None" (reportOptionalOperand)
- 4 errors, 479 warnings, 1 information 
+ 5 errors, 479 warnings, 1 information 

paroxython (https://github.com/laowantong/paroxython)
+   /tmp/mypy_primer/projects/paroxython/paroxython/cli.py:35:11 - error: No overloads for "sub" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/paroxython/paroxython/cli.py:35:44 - error: Argument of type "str | None" cannot be assigned to parameter "string" of type "str" in function "sub"
+     Type "str | None" is incompatible with type "str"
+       "None" is incompatible with "str" (reportArgumentType)
- 14 errors, 2 warnings, 0 informations 
+ 16 errors, 2 warnings, 0 informations 

pip (https://github.com/pypa/pip)
- /tmp/mypy_primer/projects/pip/src/pip/_vendor/requests/status_codes.py
-   /tmp/mypy_primer/projects/pip/src/pip/_vendor/requests/status_codes.py:121:15 - error: Expression of type "str | None" is incompatible with declared type "str"
-     Type "str | None" is incompatible with type "str"
-       "None" is incompatible with "str" (reportAssignmentType)
- 1857 errors, 44 warnings, 0 informations 
+ 1856 errors, 44 warnings, 0 informations 

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- /tmp/mypy_primer/projects/mongo-python-driver/pymongo/pool.py
-   /tmp/mypy_primer/projects/mongo-python-driver/pymongo/pool.py:21:11 - error: Expression of type "str | None" is incompatible with declared type "str"
-     Type "str | None" is incompatible with type "str"
-       "None" is incompatible with "str" (reportAssignmentType)
- 776 errors, 27 warnings, 0 informations 
+ 775 errors, 27 warnings, 0 informations 

bokeh (https://github.com/bokeh/bokeh)
+   /tmp/mypy_primer/projects/bokeh/tests/unit/bokeh/command/test___init___command.py:36:32 - error: "split" is not a known attribute of "None" (reportOptionalMemberAccess)
+   /tmp/mypy_primer/projects/bokeh/tests/unit/bokeh/command/test___init___command.py:38:16 - error: Operator "in" not supported for types "str" and "str | None"
+     Operator "in" not supported for types "str" and "None" (reportOperatorIssue)
- 3753 errors, 355 warnings, 0 informations 
+ 3755 errors, 355 warnings, 0 informations