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

实现set_arg和get_arg类方法 #2217

Closed
wants to merge 2 commits into from
Closed

实现set_arg和get_arg类方法 #2217

wants to merge 2 commits into from

Conversation

eya46
Copy link
Contributor

@eya46 eya46 commented Jul 27, 2023

实现这样的效果

@test.handle()
async def test_handle(matcher: Matcher, cmd: Annotated[Message, CommandArg()]):
    test.set_arg("key_t", cmd)
    matcher.set_arg("key", cmd)
    for index, i in enumerate([
        matcher.get_arg("key", cmd),
        test.get_arg("key_t"),
        matcher.get_arg("key"),
        test.get_arg("none", cmd),
        matcher.get_arg("none", cmd),
        test.get_arg("none"),
        matcher.get_arg("none"),
    ]):
        print(index, i)
    logger.success(cmd)

@codecov
Copy link

codecov bot commented Jul 27, 2023

Codecov Report

Merging #2217 (3ee9d86) into master (a2f2b81) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2217      +/-   ##
==========================================
+ Coverage   89.80%   89.82%   +0.01%     
==========================================
  Files          46       46              
  Lines        3345     3350       +5     
==========================================
+ Hits         3004     3009       +5     
  Misses        341      341              
Flag Coverage Δ
unittests 89.82% <100.00%> (+0.01%) ⬆️

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

Files Changed Coverage Δ
nonebot/internal/matcher/matcher.py 97.11% <100.00%> (+0.06%) ⬆️

@github-actions
Copy link
Contributor

github-actions bot commented Jul 27, 2023

🚀 Deployed on https://deploy-preview-2217--nonebot2.netlify.app

@github-actions github-actions bot temporarily deployed to pull request July 27, 2023 02:56 Inactive
@github-actions github-actions bot temporarily deployed to pull request July 27, 2023 04:57 Inactive
@@ -137,6 +137,7 @@ class Matcher(metaclass=MatcherMeta):
def __init__(self):
self.handlers = self.handlers.copy()
self.state = self._default_state.copy()
self._m_t = current_matcher.set(self)
Copy link
Member

Choose a reason for hiding this comment

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

这是在干啥?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

让Matcher()的情况也能get到matcher

但不知道该在啥时候reset,就写个变量,让它在ensure_context里被覆盖...

@eya46 eya46 closed this Jul 28, 2023
@eya46 eya46 deleted the arg branch July 31, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants