Tribler/py-ipv8

Post-ruff minor issues

Closed this issue · 3 comments

Now that all the core IPv8 logic has had its ruff issues fixed, including its types, I'm left with a list of minor issues that should be solved at some point:

  • Both TestBase and DiscoveryStrategy should be turned into Generic[SomeOverlayType]. WHY: Having to assure mypy that they were loaded with a particular type of overlay, at runtime, is a pain. Fixed in #1181 and #1192
  • Create a CommunityConfig (or a dictionary) to store Community configurations. WHY: We now have 6 arguments to the Community constructor and, not only is this triggering PLR0913 everywhere, this leads to mass repetition of the default arguments.
  • Related to the previous point: the docs should be updated accordingly.
  • PD011 is throwing false-positive numpy errors and should be disabled. WHY: We don't use numpy. Fixed in #1190
  • The RequestCache should type its return values. WHY: Currently we need to cast all of the results of pop() from the RequestCache. Fixed in #1191
  • We could shorten some types to be more descriptive. WHY: We now have very long types which are (probably) correct but - for example - one bytes may describe a 20 byte infohash while the other is a 64 byte public key. Fixed in #1197

I'll handle the TestBase generic-ification in the test folder PR.

EDIT: fixed in #1181

The RequestCache should type its return values.

To be consistent with the implementation of retrieve_cache, we can demand that NumberCaches specify a name. Then we can simply call the old pop implementation using that value (RequestCache.pop(cache.name: str, number: int)) when RequestCache(cache: CacheTypeVar, number: int) -> CacheTypeVar is invoked.

A TypedDict may be a good way to implement a CommunityConfig (or CommunitySettings) object.