fix Do not enforce name alignment for namedtuple and enum functional syntax #2874#2892
fix Do not enforce name alignment for namedtuple and enum functional syntax #2874#2892asukaminato0721 wants to merge 2 commits intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes issue #2874 by removing the diagnostic that enforced assignment-name alignment for functional Enum(...) and NamedTuple(...)/namedtuple(...) definitions, matching the behavior of other modern type checkers.
Changes:
- Stop emitting “Expected string literal
<varname>” errors for functionalEnumdefinitions whose first string argument doesn’t match the assignment target name. - Stop emitting the same alignment error for functional
typing.NamedTuple(...)andcollections.namedtuple(...)assignments (while still binding/type-checking the passed name expression). - Add regression tests covering name-mismatch cases for both functional namedtuple and functional Enum.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrefly/lib/binding/stmt.rs |
Removes name-alignment enforcement for functional namedtuple assignments; still type-checks the name expression via ensure_expr. |
pyrefly/lib/binding/class.rs |
Removes name-alignment enforcement for functional Enum synthesis. |
pyrefly/lib/test/named_tuple.rs |
Adds regression test ensuring mismatched functional namedtuple names don’t error and types are still inferred as expected. |
pyrefly/lib/test/enums.rs |
Adds regression test ensuring mismatched functional Enum names don’t error and member literals are still inferred. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: dd-trace-py (https://github.com/DataDog/dd-trace-py)
- ERROR ddtrace/vendor/psutil/_psbsd.py:868:9-15: Expected string literal "nt_mmap_grouped" [invalid-argument]
- ERROR ddtrace/vendor/psutil/_psbsd.py:871:9-15: Expected string literal "nt_mmap_ext" [invalid-argument]
- ERROR ddtrace/vendor/psutil/_pssunos.py:670:34-40: Expected string literal "nt_mmap_grouped" [invalid-argument]
- ERROR ddtrace/vendor/psutil/_pssunos.py:671:30-36: Expected string literal "nt_mmap_ext" [invalid-argument]
pycryptodome (https://github.com/Legrandin/pycryptodome)
- ERROR lib/Crypto/Cipher/_mode_gcm.py:70:28-40: Expected string literal "GHASH_Imp" [invalid-argument]
scikit-learn (https://github.com/scikit-learn/scikit-learn)
- ERROR sklearn/utils/_testing.py:840:23-29: Expected string literal "Args" [invalid-argument]
psycopg (https://github.com/psycopg/psycopg)
- ERROR tests/types/test_enum.py:351:9-18: Expected string literal "enum" [invalid-argument]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- ERROR pymongo/ocsp_cache.py:50:9-31: Expected string literal "CACHE_KEY_TYPE" [invalid-argument]
cloud-init (https://github.com/canonical/cloud-init)
- ERROR tests/unittests/sources/test_smartos.py:793:9-17: Expected string literal "res" [invalid-argument]
- ERROR tests/unittests/test_net_activators.py:48:24-31: Expected string literal "mocks" [invalid-argument]
- ERROR tests/unittests/test_net_activators.py:67:24-31: Expected string literal "mocks" [invalid-argument]
pandas (https://github.com/pandas-dev/pandas)
- ERROR pandas/core/frame.py:1440:17-21: Expected string literal "itertuple" [invalid-argument]
- ERROR pandas/tests/frame/indexing/test_indexing.py:1407:36-45: Expected string literal "indexer_tuple" [invalid-argument]
- ERROR pandas/tests/frame/test_constructors.py:1613:34-42: Expected string literal "named_tuple" [invalid-argument]
discord.py (https://github.com/Rapptz/discord.py)
- ERROR discord/enums.py:96:22-42: Expected string literal "cls" [invalid-argument]
spack (https://github.com/spack/spack)
- ERROR lib/spack/spack/test/test_suite.py:265:40-51: Expected string literal "MockSuite" [invalid-argument]
spark (https://github.com/apache/spark)
- ERROR python/pyspark/serializers.py:356:42-46: Expected string literal "cls" [invalid-argument]
|
Primer Diff Classification✅ 9 improvement(s) | ➖ 1 neutral | 10 project(s) total | -17 errors 9 improvement(s) across dd-trace-py, pycryptodome, scikit-learn, psycopg, mongo-python-driver, pandas, discord.py, spack, spark.
Detailed analysis✅ Improvement (9)dd-trace-py (-4)
pycryptodome (-1)
scikit-learn (-1)
psycopg (-1)
mongo-python-driver (-1)
pandas (-3)
discord.py (-1)
spack (-1)
spark (-1)
➖ Neutral (1)cloud-init (-3)
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (10 LLM) |
Summary
Fixes #2874
no longer enforces assignment-name alignment for functional Enum and functional NamedTuple definitions.
Test Plan
update && add test