Skip to content
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

feat[lang]: use keyword arguments for event instantiation #4257

Merged

Conversation

z80dev
Copy link
Contributor

@z80dev z80dev commented Sep 24, 2024

What I did

Closes #4249

Implement support for keyword arguments when calling event constructors

How I did it

Mainly updated code to check node.keywords instead of node.args where dealing with events and the arguments passed to the constructor.

During semantic analysis, if we detect an event instantiated with positional args, we log a warning. Semantic analysis is the first place we can deal with this problem, as during parsing we don't have access to info such as what the names of a specific events' arguments are.

This implementation is fully backwards compatible with the positional arguments syntax.

How to verify it

All unit tests have been updated to use keyword arguments for events, so passing tests give us a lot of confidence the change is correct.

In addition, a new unit test was added verifying that positional arguments still compile and work as expected.

Commit message

This commit changes event instantiation from taking positional
arguments to taking keyword arguments.

For backwards compatibility (and to ease users into v0.4.1), this
implementation is fully backwards compatible with the existing
positional arguments syntax, but a warning will be emitted if the old
syntax is encountered.

All unit tests have been updated to use keyword arguments for events,
so passing tests give us a lot of confidence the change is correct.

In addition, a new unit test was added verifying that positional
arguments still compile and work as expected.

Misc/refactors:
- Factor out `validate_kwargs()` from `StructT._ctor_call_return()`
- Rewrite the kwarg validation code for clarity
- Add `__sub__` and `__isub__` dunders to `OrderedSet`

Description for the changelog

Use kwargs for event instantiation

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@z80dev z80dev changed the title Feat: use keyword arguments for event instantiation feat[lang]: use keyword arguments for event instantiation Sep 24, 2024
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.18%. Comparing base (e21f3e8) to head (a1a5dcb).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4257      +/-   ##
==========================================
- Coverage   91.36%   90.18%   -1.19%     
==========================================
  Files         108      108              
  Lines       15637    15653      +16     
  Branches     3440     3446       +6     
==========================================
- Hits        14287    14116     -171     
- Misses        920     1066     +146     
- Partials      430      471      +41     
Flag Coverage Δ
?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@tserg tserg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment, otherwise LGTM!

Handing it over to @charles-cooper

vyper/semantics/types/user.py Outdated Show resolved Hide resolved
we don't need to set a parent node for the kw node's value
z80dev and others added 5 commits September 26, 2024 14:45
rather than converting positional arg ASTs to kwarg ASTs, we handle
kwargs alongside the existing positional arg logic
z80dev and others added 2 commits September 30, 2024 13:59
Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
Reduces duplication around EventT and StructT classes
Comment on lines +16 to +20
from vyper.semantics.analysis.utils import (
check_modifiability,
validate_expected_type,
validate_kwargs,
)

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.analysis.utils
begins an import cycle.
also update expected exception on some struct failures now that we're
using a common helper function
@z80dev
Copy link
Contributor Author

z80dev commented Oct 1, 2024

merging in master dropped the coverage a good amount but from looking at the report I don't think its related to this PR, but will look into it

@charles-cooper
Copy link
Member

merging in master dropped the coverage a good amount but from looking at the report I don't think its related to this PR, but will look into it

i wouldn't worry about it too much, the codecov app often fails to merge the coverage files properly

Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
@charles-cooper charles-cooper enabled auto-merge (squash) October 5, 2024 00:23
Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!!

@charles-cooper charles-cooper merged commit ebe3c0c into vyperlang:master Oct 5, 2024
155 checks passed
pcaversaccio added a commit to pcaversaccio/snekmate that referenced this pull request Oct 7, 2024
### 🕓 Changelog

Vyper changed event instantiation from taking positional arguments to
taking keyword arguments (see PR
[#4257](vyperlang/vyper#4257)). This PR
refactors all 🐍 snekmate event instantiations accordingly (resolves
#277). Furthermore, we configure the tests to use the latest commit from
the `master` branch of Vyper going forward, ensuring we are always
testing against the most up-to-date version of the compiler.

---------

Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VIP: Convert Event construction to use kwargs
3 participants