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

irc: rework parsing of modestrings #2131

Merged
merged 11 commits into from
Nov 11, 2021
Merged

Conversation

Exirel
Copy link
Contributor

@Exirel Exirel commented Jul 1, 2021

Description

Following the work on #2098 I was able to refactor that part of the modestring parsing I had in mind since a long time ago. My main goal was to extract the parsing logic, and separate it from the application of new modes & privileges to users.

So now there is a sopel.irc.modes module that contains only modestring parsing (with the appropriate tests), and this module is then used in the coretasks plugin. There is close to 0 change in behavior, but there is at least two I can remember:

  1. it now uses deepcopy to get the existing channel modes to prevent any mutability issues
  2. before, when something went wrong (unknown mode type), channel.modes = modes wasn't done; this is now fixed

No tests on coretasks have been modified, although I used them locally to ensure that 1. it worked as intended, and 2. without breaking changes. And yes, at first, they didn't pass, and I had to fix what was broken in my code. So I'm pretty happy about all this. As said on IRC, this wasn't possible without the work of @half-duplex that relentlessly fixed the modeparsing before.

One last thing: I used type hint on sopel.irc.modes and validated it with mypy: so far, so good. I might do more of that later. I just hope it works fine with Py3.6 because I know for a fact that type hinting changed in later versions. Further conversation need to happen around Py3.10 too, because that version might not be easy to support while supporting 3.6.

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make quality and make test)
  • I have tested the functionality of the things this change touches

@Exirel Exirel added this to the 8.0.0 milestone Jul 1, 2021
@Exirel Exirel requested review from dgw and half-duplex July 1, 2021 08:02
sopel/coretasks.py Show resolved Hide resolved
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

OK, I finally went through it. Some pretty significant questions wound up in those line notes. I was surprised, not least because I'm not that alert tonight and expected to miss stuff. x)

sopel/irc/__init__.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/coretasks.py Outdated Show resolved Hide resolved
sopel/coretasks.py Outdated Show resolved Hide resolved
sopel/coretasks.py Outdated Show resolved Hide resolved
@Exirel Exirel force-pushed the irc-modes-rework branch 2 times, most recently from 8dd8d8a to 178e392 Compare July 14, 2021 22:34
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

I'm back again! Loving the added snark peppered in the docs.

sopel/coretasks.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Show resolved Hide resolved
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

We must be getting close.

sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
@Exirel Exirel requested a review from dgw July 26, 2021 14:36
@Exirel
Copy link
Contributor Author

Exirel commented Jul 26, 2021

We are getting close.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

I deem this "close enough", mostly because the best way to find any remaining edge cases (or documentation mistakes) is going to be shipping this and having people use it in production testing environments. Squash the fixups and then bug @half-duplex (who wrote some of the logic this replaces) to take a look if he's willing.

Copy link
Member

@half-duplex half-duplex left a comment

Choose a reason for hiding this comment

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

Nice to find some cases fixed I hadn't thought of, and see the Enterprise™ version of something I wrote ^.^

sopel/coretasks.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/coretasks.py Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Outdated Show resolved Hide resolved
sopel/irc/modes.py Show resolved Hide resolved
sopel/coretasks.py Show resolved Hide resolved
sopel/coretasks.py Show resolved Hide resolved
sopel/coretasks.py Outdated Show resolved Hide resolved
@Exirel
Copy link
Contributor Author

Exirel commented Oct 28, 2021

Last round of fixes is available! Hopefully, will be the actual last one. 🤷

Copy link
Member

@half-duplex half-duplex left a comment

Choose a reason for hiding this comment

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

I'm out of enumerable nits 😛

@dgw
Copy link
Member

dgw commented Nov 7, 2021

I'm out of enumerable nits 😛

@Exirel I think this means you can squash. 🚀

Exirel and others added 4 commits November 7, 2021 10:43
Instead of creating an instance of `ModeParser` at each MODE event, the
bot has a `modeparser` attribute with appropriate default values for its
chanmodes, privileges, and param types.

For that to work, when the bot received new ISUPPORT parameters, it
updates the chanmodes and privileges of the mode parser if necessary.

This required to adapt the list of default modes, as `a` and `q` are
more commonly used as privilege rather than modes.

Tests have been updated to manually update the modeparser. This may
require new methods on the test IRC server to streamline an ISUPPORT
configuration, because right now it's a bit too manual.
Several improvements of the ModeParser.parse method, which was renamed
from ModeParser.parse_modestring (renamed to prevent name conflict with
sopel.irc.modes.parse_modestring function).

The method ModeParser.get_mode_info doesn't try to parse privileges
anymore, which make it more type-safe as the letter is now str instead
of Optional[str]. This makes the logic in ModeParser.parse a little
different in a good way.

Overall, a better type definition helped built a better interface with
less potential for issues later. Functionnal tests for ModeParser.parse
are kept the same, as nothing has change on this side.

Thanks to mal who caught the type inconsistency in the first place!
@Exirel
Copy link
Contributor Author

Exirel commented Nov 7, 2021

you can squash. 🚀

🚀 landed.

@dgw dgw merged commit a8dcb76 into sopel-irc:master Nov 11, 2021
@dgw
Copy link
Member

dgw commented Nov 11, 2021

I'm sure CI will fail thanks to #2210, but 4 months in the PR list was enough for this patch. :shipit:

@Exirel Exirel deleted the irc-modes-rework branch December 31, 2021 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants