Add `Final` for stdlib constants
Use the following script: https://gist.github.com/max-muoto/3bdfd495d4ee48dba99c16513e855983 to add Final to 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] into MY_CONSTANT: Final[Literal[1]], but I ran the Ruff rule redundant-final-literal to fix cases of this.
Otherwise:
MY_CONSTANT = 1
MY_CONSTANT_2: int = 1
# Becomes:
MY_CONSTANT: Final = 1
MY_CONSTANT_2: Final[int] = 1
With TypeVar, ParamSpec, TypeVarTuple, and NewType excluded.
Additionally, ths this excludes the wintypes.pyi module (see commit here), adding final leads Pyright to raise a Variable not allowed in type expression warning. 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 _TypeVar that my script didn't account, and removing an extra import of Final in typing.pyi and typing_extensions.pyi.
Diff from mypy_primer, showing the effect of this PR on open source code:
python-sop (https://gitlab.com/dkg/python-sop)
+ sop/__init__.py:424: error: Returning Any from function declared to return "datetime | None" [no-any-return]
+ sop/__init__.py:424: error: _T? not callable [misc]
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]
SinbadCogs (https://github.com/mikeshardmind/SinbadCogs)
+ rolemanagement/events.py:41: error: _T? not callable [misc]
+ embedmaker/serialize.py:81: error: _T? not callable [misc]
+ antimentionspam/antimentionspam.py:239: error: _T? not callable [misc]
+ scheduler/time_utils.py:42: error: _T? not callable [misc]
+ embedmaker/time_utils.py:42: error: _T? not callable [misc]
+ scheduler/message.py:82: error: _T? not callable [misc]
+ modnotes/modnotes.py:148: error: _T? not callable [misc]
dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ddtrace/internal/flare/flare.py:70: error: No overload variant of "getLevelName" matches argument type "str" [call-overload]
+ ddtrace/internal/flare/flare.py:70: note: Possible overload variant:
+ ddtrace/internal/flare/flare.py:70: note: def getLevelName(level: int) -> str
+ ddtrace/internal/debug.py:121: error: _T? not callable [misc]
+ ddtrace/profiling/exporter/http.py:218: error: _T? not callable [misc]
+ ddtrace/profiling/exporter/http.py:219: error: _T? not callable [misc]
cloud-init (https://github.com/canonical/cloud-init)
+ tests/integration_tests/clouds.py:328: error: _T? not callable [misc]
+ cloudinit/sources/azure/errors.py:55: error: _T? not callable [misc]
+ cloudinit/sources/azure/kvp.py:52: error: _T? not callable [misc]
+ tests/unittests/sources/azure/test_kvp.py:14: error: _T? not callable [misc]
+ tests/unittests/cmd/devel/test_logs.py:65: error: _T? not callable [misc]
+ tests/unittests/cmd/devel/test_logs.py:181: error: _T? not callable [misc]
+ tests/integration_tests/test_paths.py:75: error: _T? not callable [misc]
+ tests/integration_tests/test_paths.py:107: error: _T? not callable [misc]
pytest (https://github.com/pytest-dev/pytest)
+ src/_pytest/logging.py:518: error: No overload variant of "getLevelName" matches argument type "str" [call-overload]
+ src/_pytest/logging.py:518: note: Possible overload variant:
+ src/_pytest/logging.py:518: note: def getLevelName(level: int) -> str
pydantic (https://github.com/pydantic/pydantic)
- pydantic/v1/validators.py:614: note: Possible overload variants:
+ pydantic/v1/validators.py:614: note: Possible overload variant:
- pydantic/v1/validators.py:614: note: def __init__(self, str, None = ..., /, **kwargs: Any) -> NamedTupleT
+ pydantic/deprecated/parse.py:78: error: _T? not callable [misc]
+ pydantic/deprecated/json.py:131: error: _T? not callable [misc]
+ pydantic/main.py:1160: error: _T? not callable [misc]
+ pydantic/main.py:1212: error: _T? not callable [misc]
+ pydantic/main.py:1219: error: _T? not callable [misc]
+ pydantic/deprecated/tools.py:101: error: _T? not callable [misc]
+ pydantic/deprecated/class_validators.py:198: error: _T? not callable [misc]
+ pydantic/deprecated/decorator.py:38: error: _T? not callable [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
discord.py (https://github.com/Rapptz/discord.py)
+ discord/member.py:920: error: _T? not callable [misc]
+ discord/member.py:976: error: _T? not callable [misc]
openlibrary (https://github.com/internetarchive/openlibrary)
+ openlibrary/core/yearly_reading_goals.py: note: In member "update_current_count" of class "YearlyReadingGoals":
+ openlibrary/core/yearly_reading_goals.py:103: error: _T? not callable [misc]
+ openlibrary/core/yearly_reading_goals.py: note: In member "update_target" of class "YearlyReadingGoals":
+ openlibrary/core/yearly_reading_goals.py:121: error: _T? not callable [misc]
+ openlibrary/core/edits.py: note: In member "assign_request" of class "CommunityEditsQueue":
+ openlibrary/core/edits.py:231: error: _T? not callable [misc]
+ openlibrary/core/edits.py: note: In member "unassign_request" of class "CommunityEditsQueue":
+ openlibrary/core/edits.py:251: error: _T? not callable [misc]
+ openlibrary/core/edits.py: note: In member "update_request_status" of class "CommunityEditsQueue":
+ openlibrary/core/edits.py:280: error: _T? not callable [misc]
+ openlibrary/core/edits.py: note: In member "comment_request" of class "CommunityEditsQueue":
+ openlibrary/core/edits.py:296: error: _T? not callable [misc]
+ openlibrary/core/edits.py: note: In member "create_comment" of class "CommunityEditsQueue":
+ openlibrary/core/edits.py:322: error: _T? not callable [misc]
+ openlibrary/plugins/upstream/borrow.py: note: In function "is_loaned_out":
+ openlibrary/plugins/upstream/borrow.py:596: error: _T? not callable [misc]
+ openlibrary/plugins/upstream/borrow.py: note: In function "_update_loan_status":
+ openlibrary/plugins/upstream/borrow.py:627: error: _T? not callable [misc]
+ openlibrary/plugins/upstream/borrow.py: note: In function "get_ia_auth_dict":
+ openlibrary/plugins/upstream/borrow.py:818: error: _T? not callable [misc]
+ openlibrary/plugins/upstream/addbook.py: note: In function "get_recaptcha":
+ openlibrary/plugins/upstream/addbook.py:50: error: _T? not callable [misc]
speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)
+ backend/api/api_wrappers.py:56: error: _T? not callable [misc]
+ backend/services/user_updater.py:78: error: _T? not callable [misc]
+ backend/api/core_api.py:36: error: _T? not callable [misc]
+ backend/api/core_api.py:37: error: _T? not callable [misc]
+ backend/api/global_scoreboard_api.py:76: error: _T? not callable [misc]
freqtrade (https://github.com/freqtrade/freqtrade)
+ freqtrade/rpc/api_server/api_ws.py:42: error: _T? not callable [misc]
pwndbg (https://github.com/pwndbg/pwndbg)
+ pwndbg/gdblib/qemu.py: note: In function "pid":
+ pwndbg/gdblib/qemu.py:93: error: _T? not callable [misc]
+ pwndbg/gdblib/qemu.py:104: error: _T? not callable [misc]
alerta (https://github.com/alerta/alerta)
+ alerta/dev.py:4: error: _T? not callable [misc]
+ alerta/utils/audit.py:94: error: _T? not callable [misc]
+ alerta/models/note.py:25: error: _T? not callable [misc]
+ alerta/models/key.py:31: error: _T? not callable [misc]
+ alerta/models/key.py:42: error: _T? not callable [misc]
+ alerta/models/key.py:164: error: _T? not callable [misc]
+ alerta/models/heartbeat.py:56: error: _T? not callable [misc]
+ alerta/models/heartbeat.py:59: error: _T? not callable [misc]
+ alerta/models/heartbeat.py:61: error: _T? not callable [misc]
+ alerta/models/blackout.py:37: error: _T? not callable [misc]
+ alerta/models/blackout.py:60: error: _T? not callable [misc]
+ alerta/models/alert.py:66: error: _T? not callable [misc]
+ alerta/models/alert.py:75: error: _T? not callable [misc]
+ alerta/models/alert.py:282: error: _T? not callable [misc]
+ alerta/models/alert.py:335: error: _T? not callable [misc]
+ alerta/models/alert.py:379: error: _T? not callable [misc]
+ alerta/models/alert.py:430: error: _T? not callable [misc]
+ alerta/models/alert.py:574: error: _T? not callable [misc]
+ alerta/models/alert.py:609: error: _T? not callable [misc]
+ alerta/models/alert.py:637: error: _T? not callable [misc]
+ alerta/auth/utils.py:52: error: _T? not callable [misc]
+ alerta/models/user.py:41: error: _T? not callable [misc]
+ alerta/models/user.py:44: error: _T? not callable [misc]
+ alerta/database/backends/mongodb/utils.py:250: error: _T? not callable [misc]
+ alerta/database/backends/mongodb/utils.py:252: error: _T? not callable [misc]
+ alerta/database/backends/mongodb/utils.py:254: error: _T? not callable [misc]
+ alerta/database/backends/mongodb/utils.py:345: error: _T? not callable [misc]
+ alerta/database/backends/mongodb/utils.py:347: error: _T? not callable [misc]
paasta (https://github.com/yelp/paasta)
+ paasta_tools/utils.py:1494: error: _T? not callable [misc]
+ paasta_tools/utils.py:3661: error: _T? not callable [misc]
+ paasta_tools/utils.py:3668: error: _T? not callable [misc]
+ paasta_tools/utils.py:3676: error: _T? not callable [misc]
+ paasta_tools/cli/cmds/status.py:713: error: _T? not callable [misc]
+ paasta_tools/cli/cmds/status.py:1860: error: _T? not callable [misc]
+ paasta_tools/cli/cmds/logs.py:1020: error: _T? not callable [misc]
+ paasta_tools/cli/cmds/logs.py:1310: error: _T? not callable [misc]
+ paasta_tools/cli/cmds/logs.py:1317: error: _T? not callable [misc]
+ paasta_tools/cli/cmds/logs.py:1329: error: _T? not callable [misc]
tornado (https://github.com/tornadoweb/tornado)
+ tornado/autoreload.py:339: error: _T? not callable [misc]
+ tornado/test/httputil_test.py:444: error: _T? not callable [misc]
+ tornado/test/httpclient_test.py:916: error: _T? not callable [misc]
bandersnatch (https://github.com/pypa/bandersnatch)
+ src/bandersnatch/utils.py: note: In function "make_time_stamp":
+ src/bandersnatch/utils.py:54: error: _T? not callable [misc]
+ src/bandersnatch/mirror.py: note: In member "synchronize" of class "Mirror":
+ src/bandersnatch/mirror.py:58: error: _T? not callable [misc]
dragonchain (https://github.com/dragonchain/dragonchain)
+ dragonchain/lib/dto/smart_contract_model.py:100:86: error: _T? not callable [misc]
+ dragonchain/lib/dto/smart_contract_model.py:300:112: error: _T? not callable [misc]
+ dragonchain/lib/authorization.py:51:12: error: _T? not callable [misc]
+ dragonchain/scheduler/scheduler.py:65:42: error: _T? not callable [misc]
mkosi (https://github.com/systemd/mkosi)
+ mkosi/log.py:92:34: error: No overload variant of "getLevelName" matches argument type "str" [call-overload]
+ mkosi/log.py:92:34: note: Possible overload variant:
+ mkosi/log.py:92:34: note: def getLevelName(level: int) -> str
typeshed-stats (https://github.com/AlexWaygood/typeshed-stats)
+ website_macros.py:101: error: _T? not callable [misc]
mkdocs (https://github.com/mkdocs/mkdocs)
+ mkdocs/tests/__init__.py:4: error: Cannot assign to final name "_MAX_LENGTH" [misc]
jax (https://github.com/google/jax)
+ jax/_src/scipy/optimize/_lbfgs.py:146: error: _T? not callable [misc]
materialize (https://github.com/MaterializeInc/materialize)
+ misc/python/materialize/buildkite_insights/util/data_io.py:75: error: _T? not callable [misc]
+ ci/cleanup/launchdarkly.py:32: error: _T? not callable [misc]
- misc/python/materialize/scratch.py:388: error: Unsupported operand types for > ("float" and "str") [operator]
+ misc/python/materialize/scratch.py:388: error: _T? not callable [misc]
+ misc/python/materialize/cli/cloudbench.py:290: error: _T? not callable [misc]
+ misc/python/materialize/cli/scratch/create.py:148: error: _T? not callable [misc]
+ ci/load/periodic.py:31: error: _T? not callable [misc]
+ ci/load/periodic.py:36: error: _T? not callable [misc]
+ ci/cleanup/aws.py:107: error: _T? not callable [misc]
pytest-robotframework (https://github.com/detachhead/pytest-robotframework)
+ pytest_robotframework/__init__.py:322: error: _T? not callable [misc]
- pytest_robotframework/__init__.py:330: error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader [misc]
- pytest_robotframework/__init__.py:464: error: Overloaded function signature 5 will never be matched: signature 4's parameter type(s) are the same or broader [misc]
+ pytest_robotframework/__init__.py:460: error: _T? not callable [misc]
- pytest_robotframework/__init__.py:468: error: Overloaded function signature 6 will never be matched: signature 5's parameter type(s) are the same or broader [misc]
- pytest_robotframework/__init__.py:570: note: def keyword(fn: Any) -> NoReturn
mitmproxy (https://github.com/mitmproxy/mitmproxy)
- mitmproxy/utils/debug.py:60: error: Incompatible types in assignment (expression has type "pconn", variable has type "popenfile") [assignment]
+ mitmproxy/utils/debug.py:60: error: _T? not callable [misc]
+ mitmproxy/log.py:193: error: Argument "level" to "log" of "Logger" has incompatible type "str"; expected "int" [arg-type]
pyodide (https://github.com/pyodide/pyodide)
+ pyodide-build/pyodide_build/xbuildenv_releases.py:227: error: _T? not callable [misc]
+ pyodide-build/pyodide_build/xbuildenv_releases.py:229: error: _T? not callable [misc]
+ pyodide-build/pyodide_build/buildall.py:191: error: _T? not callable [misc]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/context/base.py:58: error: _T? not callable [misc]
+ tanjun/context/base.py:133: error: _T? not callable [misc]
+ tanjun/context/base.py:136: error: _T? not callable [misc]
+ tanjun/context/slash.py:321: error: _T? not callable [misc]
+ tanjun/context/slash.py:1042: error: _T? not callable [misc]
+ tanjun/context/slash.py:1077: error: _T? not callable [misc]
+ tanjun/context/slash.py:1085: error: _T? not callable [misc]
+ tanjun/context/message.py:114: error: _T? not callable [misc]
+ tanjun/context/message.py:184: error: _T? not callable [misc]
+ tanjun/context/message.py:189: error: _T? not callable [misc]
+ tanjun/context/autocomplete.py:95: error: _T? not callable [misc]
+ tanjun/context/menu.py:98: error: _T? not callable [misc]
+ tanjun/context/menu.py:153: error: _T? not callable [misc]
+ tanjun/context/menu.py:156: error: _T? not callable [misc]
+ tanjun/commands/slash.py:1931: error: _T? not callable [misc]
+ tanjun/commands/slash.py:2127: error: _T? not callable [misc]
+ tanjun/commands/slash.py:2283: error: _T? not callable [misc]
+ tanjun/clients.py:601: error: _T? not callable [misc]
+ tanjun/clients.py:913: error: _T? not callable [misc]
+ tanjun/clients.py:1004: error: Returning Any from function declared to return "Client" [no-any-return]
+ tanjun/clients.py:1005: error: No overload variant of "Client" matches argument types "RESTClient", "Optional[Cache]", "EventManager", "_GatewayBotProto", "VoiceComponent", "bool", "Optional[Client]", "bool", "Union[Sequence[Union[PartialGuild, Union[Snowflake, int]]], Union[PartialGuild, Union[Snowflake, int]], bool]", "Union[Union[PartialGuild, Union[Snowflake, int]], bool]", "Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]]", "Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]]", "Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]]", "int" [call-overload]
+ tanjun/clients.py:1005: note: Possible overload variant:
+ tanjun/clients.py:1005: note: def __init__(self, rest: RESTClient, *, cache: Optional[Cache] = ..., events: Optional[EventManager] = ..., server: Optional[InteractionServer] = ..., shards: Optional[ShardAware] = ..., voice: Optional[VoiceComponent] = ..., event_managed: bool = ..., injector: Optional[Client] = ..., mention_prefix: bool = ..., declare_global_commands: Union[Sequence[Union[PartialGuild, Union[Snowflake, int]]], Union[PartialGuild, Union[Snowflake, int]], bool] = ..., command_ids: Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]] = ..., message_ids: Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]] = ..., user_ids: Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]] = ...) -> Client
+ tanjun/clients.py:1005: error: Not all union combinations were tried because there are too many unions [misc]
+ tanjun/clients.py:1042: error: _T? not callable [misc]
+ tanjun/clients.py:1129: error: No overload variant of "Client" matches argument types "RESTClient", "InteractionServer", "Union[Sequence[Union[PartialGuild, Union[Snowflake, int]]], Union[PartialGuild, Union[Snowflake, int]], bool]", "Optional[Client]", "Union[Union[PartialGuild, Union[Snowflake, int]], bool]", "Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]]", "Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]]", "Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]]", "int" [call-overload]
+ tanjun/clients.py:1129: note: Possible overload variant:
+ tanjun/clients.py:1129: note: def __init__(self, rest: RESTClient, *, cache: Optional[Cache] = ..., events: Optional[EventManager] = ..., server: Optional[InteractionServer] = ..., shards: Optional[ShardAware] = ..., voice: Optional[VoiceComponent] = ..., event_managed: bool = ..., injector: Optional[Client] = ..., mention_prefix: bool = ..., declare_global_commands: Union[Sequence[Union[PartialGuild, Union[Snowflake, int]]], Union[PartialGuild, Union[Snowflake, int]], bool] = ..., command_ids: Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]] = ..., message_ids: Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]] = ..., user_ids: Optional[Mapping[str, Union[PartialCommand, Union[Snowflake, int]]]] = ...) -> Client
+ tanjun/clients.py:1129: error: Not all union combinations were tried because there are too many unions [misc]
+ tanjun/clients.py:1145: error: Returning Any from function declared to return "Client" [no-any-return]
+ tanjun/annotations.py:1698: error: _T? not callable [misc]
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/runtime/credentials.py: note: In function "_send_email":
+ lib/streamlit/runtime/credentials.py:85:10: error: _T? not callable [misc]
I think this uncovered a PyType bug, it choked on this (I think believing it was associated with the RegexFlag enum). Reverted the change for this one line: https://github.com/python/typeshed/pull/12318/commits/76720eca1f4b3c46779432c3cf7d535063886481
Edit: Same issue here.
We probably can't merge this with all the mysterious new error: _T? not callable. I'm not sure what's causing that, maybe the new imports messed up mypy's handling of the builtin import cycle.
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]
We probably can't merge this with all the mysterious new
error: _T? not callable. I'm not sure what's causing that, maybe the new imports messed up mypy's handling of the builtin import cycle.
That's from an older run, it's not occurring anymore if you look at the latest mypy primer. (I accidentally had some Final = _TypeVar cases that I had to fix manually, my script only accounted for typing.TypeVar and TypeVar)
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]
Okay, consolidated the commits fixing PyType related stuff: https://github.com/python/typeshed/pull/12318/commits/abb0a27d50632ffd4e7bde52bd45a99a91f52257
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.
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]
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 = 42
And 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]
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.