Skip to content
Snippets Groups Projects
  1. Dec 15, 2024
    • Georges Racinet's avatar
      rust-pyo3-sharedref: reworked constructors · d85514a8
      Georges Racinet authored
      We had previously duplicated the `new` associated function on
      `PySharedRef` with a method on `PySharedRefCell`: in `rust-cpython`,
      the former was hidden by the accessor defined by the `py_class!` macro,
      which we did not port yet.
      
      On `PySharedRefCell` itself, replacing the `new` associated function
      by the `From` trait carries all the needed semantics, and has the
      advantage of less repetititons of the type name, which will help
      with further refactorings and renamings.
      d85514a8
  2. Dec 14, 2024
    • Georges Racinet's avatar
      rust-pyo3-sharedref: converted integration tests from rust-cpython · a7d2529e
      Georges Racinet authored
      This should bring full confidence on the conversion to PyO3.
      It highlights also the difference between the two bindings systems:
      in PyO3, the struct defined by the user is the inner Rust one.
      In rust-cpython, it is the wrapped one exposed to CPythob
      
      We enclose some of the boilerplate in helper functions.
      Perhaps we should first import the rust-cpython integration test,
      rework it with the same helpers, then only change the helpers.
      a7d2529e
  3. Dec 15, 2024
    • Georges Racinet's avatar
      rust-pyo3: initial port of PySharedRef · be765f67
      Georges Racinet authored
      At this point, we have a full translation, with some tests.
      The tests are high level, demonstrating the case of iterating over
      `HashSet` as a doctest. The assertions are written as Python statements,
      in order not to be obscure and to resist later refactorings.
      The rust-cpython integration tests will be ported in a subsequent changeset.
      
      We find the example of iterating over `HashSet` to be more convincing than
      the iterating over `Vec`, the example provided in rust-cpython, because
      in the case of `Vec`, it would be simple enough to use `Arc<Vec>` and
      an index. This would of course be reimplementing the iterator, but is simple
      enough that it leads the reader to believe that having a reference is the
      problem, whereas the problem is having a reference that is itself enclosed
      in a type with lifetime that can be arbitrary complex. It took us some
      time to remember that subtlety, and hence we reworded the documentation
      to stress that point.
      
      We decided to put this work a separate crate, which makes running `cargo test`
      work for the crate, but not for the entire workspace: the `extension-module`
      feature gets in the way. That is why we reexpose the feature on `hg-pyo3` as
      default and run the tests with `--no-default-feature` in Makefile, hence in CI.
      
      An important difference with rust-cpython is that everything has to be `Sync`,
      hence we replace `RefCell` with `RwLock` and only speak of "interior mutability"
      in the documentation. Since everything happens in `hg-pyo3` behind the GIL,
      there is at this point no reason to use `read()` and `write()` instead of
      respectively `try_read()` and `try_write()`. But PyO3 is aiming to support
      free-threaded Python (without GIL), and `PySharedRef` should therefore
      allow waiting for its inner locks.
      be765f67
  4. Dec 17, 2024
    • Matt Harbison's avatar
    • Matt Harbison's avatar
      cmdutil: switch the `mode` on `cmdutil.makefileobj()` to str · 89215c5b
      Matt Harbison authored
      I think the typing around whether `open()` returns `IO[bytes]` or `IO[str]`
      hinges on the content of the mode string.  Converting from bytes instead of
      using a literal can suppress that (though PyCharm currently complains about
      this).  Instead, we can mandate the use of a (vastly reduced) set of mode
      options.  For now, none of the 3 callers provide this argument, so it's not a
      big deal.  Ideally, this would always enforce binary mode.
      
      There's a little extra typing required to pull this off.  The `_unclosablefile`
      class can't subclass `typing.BinaryIO`, because there were a bunch of test
      failures around writing to stdout.  Strangely, pytype didn't complain that the
      abstract methods on `typing.BinaryIO` weren't overridden in this case.  Whatever
      was going on, it's a simple proxy class, so we can just cast to the expected
      type in the one place it is used.
      89215c5b
  5. Jan 01, 2025
  6. Dec 05, 2024
  7. Jan 01, 2025
    • Matt Harbison's avatar
      archival: switch the archive `kind` argument from bytes to str · 1756f5a7
      Matt Harbison authored
      This is intertwined with the `mode`, which is also used with `open()`, so the
      goal is to get that to str so that the `pycompat.open()` call can be dropped.
      Start simple because I had issues where the generated archive in some tests had
      1 different byte for some reason when making the full change, even though the
      content was binary equivalent when doing a Folder Compare of the archives with
      BeyondCompare4.
      
      The key for the `archivers` map is left alone for now.  The classes that are
      stored are only ever called with 2 args, so this should be safe.
      1756f5a7
  8. Dec 05, 2024
    • Matt Harbison's avatar
      archival: use str for a ValueError argument · cd7dcccc
      Matt Harbison authored
      Builtin exceptions generally use str, and this was probably a side effect of the
      mass-byteification a few years ago.  While we're here, specify that the type
      needs to be bytes, since that's what's checked.  Maybe this was meant to be a
      ProgrammingError- IDK that showing this to the user is helpful in any way.
      cd7dcccc
  9. Jan 02, 2025
  10. Jan 04, 2025
  11. Jan 02, 2025
  12. Jan 06, 2025
  13. Dec 31, 2024
  14. Dec 30, 2024
  15. Jan 06, 2025
  16. Dec 30, 2024
  17. Dec 17, 2024
  18. Dec 16, 2024
    • Matt Harbison's avatar
    • Matt Harbison's avatar
      pure: add an "abstractmethod" and some type hints to parsers.py to help pytype · 8de9bab8
      Matt Harbison authored
      It looks like `BaseIndexObject` is meant to be a base class with common
      implementation across the subclasses.  Both subclasses provide the class attrs
      typed here, as well as `_calculate_index()` that are accessed by the base class.
      The trick is, `revlog.RustIndexProxy` also uses it as a base class, and forwards
      some methods such that it doesn't want or need this method.  This is kind of a
      workaround to keep everything happy.
      
      Likewise, it doesn't need the 3 class variables, because it overrides the
      methods in this class that use them.  But there's no way to conditionally
      declare these.  Their presence seems conditional on the version of Python- see
      199b0e62b403.  (Also, it looks like the rust class doesn't override `append()`,
      which would need `_extra`.  Not sure if this is an oversight, or if it's more of
      a "protected" field instead of private.)
      
      `PersistentNodeMapIndexObject` says it's for debugging, so I'm not going to
      bother trying to figure out what the 3 required class attr types are right now,
      and risk introducing a cycle that confuses pytype.
      8de9bab8
  19. Dec 17, 2024
Loading