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

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

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

feat: use keyword arguments for event instantiation

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

For backwards compatibility (and to ease users into v0.4.1), the old
syntax is still supported, but a warning will be emitted.

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>
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