stubgen: Preserve simple defaults in function signatures#15355
stubgen: Preserve simple defaults in function signatures#15355JelleZijlstra merged 9 commits intopython:masterfrom
Conversation
|
Some questions for Alex and Jelle:
|
|
I installed the following packages matplotlib==3.7.1
numpy==1.24.3
pandas==2.0.2
scipy==1.10.1
seaborn==0.12.2and generated their stubs with mypy master then added defaults with stubdefaulter then compared the result with defaults added by this PR. The only differences I saw were related to the runtime vs static nature of the two tools:
Please let me know if you have other ideas to test this change. |
|
@CodiumAI-Agent please review |
This comment was marked as spam.
This comment was marked as spam.
|
@coditamar Please stop, or I'll have to report your account |
OK. I apologize. thank you |
|
Hello! May I ask what's the status of this? 🙂 thank you! |
I don’t have an answer for you but if you need default values in stub files now I invite you to try https://github.com/JelleZijlstra/stubdefaulter. I use it regularly and it works very well. |
| if rvalue.name in ("None", "True", "False"): | ||
| return rvalue.name, True | ||
| elif isinstance(rvalue, (IntExpr, FloatExpr)): | ||
| return f"{rvalue.value}", True |
There was a problem hiding this comment.
Would this work correctly for NaN and infinity?
There was a problem hiding this comment.
Would this work correctly for NaN and infinity?
Do these have a literal syntax? float("nan") is a call expression that is ignored when used as a default value in the current implementation. I'll add a test.
test-data/unit/stubgen.test
Outdated
| def f(x=b'foo',y=b"what's up"): ... | ||
| [out] | ||
| def f(x: bytes = ...) -> None: ... | ||
| def f(x: bytes = b'foo', y: bytes = b"what's up") -> None: ... |
There was a problem hiding this comment.
Can you add tests for bytes containing non-ASCII characters? Not convinced that would be handled correctly.
This comment has been minimized.
This comment has been minimized.
for more information, see https://pre-commit.ci
|
Diff from mypy_primer, showing the effect of this PR on open source code: discord.py (https://github.com/Rapptz/discord.py): typechecking got 1.07x faster (189.3s -> 177.3s)
(Performance measurements are based on a single noisy sample)
|
Fixes #13238
See also python/typeshed#8988
cc @AlexWaygood @JelleZijlstra