-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stubgen: Preserve simple defaults in function signatures #15355
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.2 and 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this work correctly for NaN and infinity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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