Conversation
This comment has been minimized.
This comment has been minimized.
|
We probably can't merge this with all the mysterious new |
This comment has been minimized.
This comment has been minimized.
That's from an older run, it's not occurring anymore if you look at the latest mypy primer. (I accidentally had some |
This comment has been minimized.
This comment has been minimized.
6e1f5a1 to
abb0a27
Compare
|
Okay, consolidated the commits fixing PyType related stuff: abb0a27 I there's two issues here (the enum one mentioned above) and another with callables, I'll report both, and once they're fixed this commit can be unwinded. |
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/ext/autodoc/importer.py: note: In function "import_object":
+ sphinx/ext/autodoc/importer.py:183:25: error: Cannot assign to final name "TYPE_CHECKING" [misc]
+ sphinx/ext/autodoc/importer.py:189:25: error: Cannot assign to final name "TYPE_CHECKING" [misc]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/util/ssl_.py:136: error: Cannot assign to final name "OP_NO_COMPRESSION" [misc]
+ src/urllib3/util/ssl_.py:136: note: Error code "misc" not covered by "type: ignore" comment
+ src/urllib3/util/ssl_.py:137: error: Cannot assign to final name "OP_NO_TICKET" [misc]
+ src/urllib3/util/ssl_.py:137: note: Error code "misc" not covered by "type: ignore" comment
+ src/urllib3/util/ssl_.py:140: error: Cannot assign to final name "PROTOCOL_TLS" [misc]
+ src/urllib3/util/ssl_.py:140: note: Error code "misc" not covered by "type: ignore" comment
+ src/urllib3/util/ssl_.py:141: error: Cannot assign to final name "PROTOCOL_TLS_CLIENT" [misc]
+ src/urllib3/util/ssl_.py:141: note: Error code "misc" not covered by "type: ignore" comment
mkdocs (https://github.com/mkdocs/mkdocs)
+ mkdocs/tests/__init__.py:4: error: Cannot assign to final name "_MAX_LENGTH" [misc]
setuptools (https://github.com/pypa/setuptools)
+ setuptools/tests/contexts.py:74: error: Cannot assign to final name "ENABLE_USER_SITE" [misc]
|
|
It might be good to split this into two PRs: a first PR that makes changes like this, which are arguably no-brainers; we can merge this first PR quickly and easily: - FOO: Literal[42]
+ FOO: Final = 42And a second PR that makes changes like this, which will probably require more careful review from us: - BAR = 42
+ BAR: Final = 42
- BAZ: int
+ BAZ: Final[int] |
Sounds good - let me split out that first change. |
Use the following script: https://gist.github.com/max-muoto/3bdfd495d4ee48dba99c16513e855983 to add
Finalto all module-level standard library constants. (Used libcst as opposed to the native ast module, since it was the easiest way to preserve comments/formatting details across all modules)Technically this script makes
MY_CONSTANT: Literal[1]intoMY_CONSTANT: Final[Literal[1]], but I ran the Ruff ruleredundant-final-literalto fix cases of this.Otherwise:
With
TypeVar,ParamSpec,TypeVarTuple, andNewTypeexcluded.Additionally, ths this excludes the
wintypes.pyimodule (see commit here), adding final leads Pyright to raise aVariable not allowed in type expressionwarning. I'll dig a bit deeper post this going out, and possibly put up an issue on Pyright's end, since this initially seems like a bug to me.The other commits on this PR are mostly fixing things like
_TypeVarthat my script didn't account, and removing an extra import ofFinalintyping.pyiandtyping_extensions.pyi.