##// END OF EJS Templates
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10...
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10 I'm not sure why the same version of pytype passed in CI with Python 3.11. What's failing on 3.10 is related to `statedata`, which is keyed on bytes, but has various value types. It looks like these several types are treated as a union when run with 3.10, and then all of them need to have the same attributes. This will take awhile to untangle, because `TypedDict` requires str keys, so we'll either have to change the keys (and whoever calls this), or migrate to a class with typed fields (and change all of the callers). There are some changes to this module currently in-flight, so I'm opting for the minimal changes here to minimally affect that, while keeping my ability to run pytype locally and track the changes. It's worth pointing out that I'm starting to use py3.9 type hints here, i.e. `Foo | None` instead of `Optional[Foo]`. That's fine even with py3.8 support because of the `from __future__ import annotations`, which delays evaluation. We already don't support pytype checking with all of the runtime supported versions of Python since at least 0851d94bfdaa, with the `ByteString` usage. The errors at the start of this series were: File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 238, in _graft_revisions: No attribute 'get' on bool [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 238, in _graft_revisions: No attribute 'get' on bytes [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 239, in _graft_revisions: No attribute 'get' on bool [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 239, in _graft_revisions: No attribute 'get' on bytes [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 241, in _graft_revisions: No attribute 'get' on bool [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 241, in _graft_revisions: No attribute 'get' on bytes [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 260, in _graft_revisions: unsupported operand type(s) for item assignment: bool [unsupported-operands] No attribute '__setitem__' on bool Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 260, in _graft_revisions: unsupported operand type(s) for item assignment: bytes [unsupported-operands] No attribute '__setitem__' on bytes Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 270, in _graft_revisions: No attribute 'get' on bool [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 270, in _graft_revisions: No attribute 'get' on bytes [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 280, in _graft_revisions: No attribute 'get' on bool [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft File "/mnt/c/Users/Matt/hg/mercurial/cmd_impls/graft.py", line 280, in _graft_revisions: No attribute 'get' on bytes [attribute-error] In Union[Any, Callable, Dict[bytes, Optional[Any]], bool, bytes, dict] Called from (traceback): line 21, in cmd_graft

File last commit:

r46195:426294d0 default
r53248:9042ffea default
Show More
clientext.rs
133 lines | 4.0 KiB | application/rls-services+xml | RustLexer
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 // Copyright 2018 Yuya Nishihara <yuya@tcha.org>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
//! cHg extensions to command server client.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 use bytes::{BufMut, BytesMut};
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 use std::ffi::OsStr;
Yuya Nishihara
rust-chg: add interface to run "validate" request...
r45171 use std::io;
Yuya Nishihara
rust-chg: send client side umask to server...
r45174 use std::mem;
Yuya Nishihara
rust-chg: add interface to chdir the server
r40014 use std::os::unix::ffi::OsStrExt;
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 use std::os::unix::io::AsRawFd;
Yuya Nishihara
rust-chg: add interface to chdir the server
r40014 use std::path::Path;
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 use tokio_hglib::UnixClient;
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 use crate::attachio;
use crate::message::{self, Instruction, ServerSpec};
use crate::runcommand;
Yuya Nishihara
rust-chg: use "crate::" to import local modules...
r45180 use crate::uihandler::SystemHandler;
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 /// Command-server client that also supports cHg extensions.
pub struct ChgClient {
client: UnixClient,
}
impl ChgClient {
/// Connects to a command server listening at the specified socket path.
pub async fn connect(path: impl AsRef<Path>) -> io::Result<Self> {
let client = UnixClient::connect(path).await?;
Ok(ChgClient { client })
}
/// Server capabilities, encoding, etc.
pub fn server_spec(&self) -> &ServerSpec {
self.client.server_spec()
}
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 /// Attaches the client file descriptors to the server.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn attach_io(
&mut self,
stdin: &impl AsRawFd,
stdout: &impl AsRawFd,
stderr: &impl AsRawFd,
) -> io::Result<()> {
Martin von Zweigbergk
rust: move rustfmt.toml to repo root so it can be used by `hg fix`...
r46195 attachio::attach_io(
self.client.borrow_protocol_mut(),
stdin,
stdout,
stderr,
)
.await
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 }
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013
Yuya Nishihara
rust-chg: add interface to chdir the server
r40014 /// Changes the working directory of the server.
Martin von Zweigbergk
rust: move rustfmt.toml to repo root so it can be used by `hg fix`...
r46195 pub async fn set_current_dir(
&mut self,
dir: impl AsRef<Path>,
) -> io::Result<()> {
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 let dir_bytes = dir.as_ref().as_os_str().as_bytes().to_owned();
self.client
.borrow_protocol_mut()
.send_command_with_args("chdir", dir_bytes)
.await
}
Yuya Nishihara
rust-chg: add interface to chdir the server
r40014
Yuya Nishihara
rust-chg: send client-side environment variables to server...
r45165 /// Updates the environment variables of the server.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn set_env_vars_os(
&mut self,
Yuya Nishihara
rust-chg: leverage impl trait at argument position...
r45183 vars: impl IntoIterator<Item = (impl AsRef<OsStr>, impl AsRef<OsStr>)>,
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 ) -> io::Result<()> {
self.client
.borrow_protocol_mut()
.send_command_with_args("setenv", message::pack_env_vars_os(vars))
.await
}
Yuya Nishihara
rust-chg: send client-side environment variables to server...
r45165
Yuya Nishihara
rust-chg: update name of the server process...
r45175 /// Changes the process title of the server.
Martin von Zweigbergk
rust: move rustfmt.toml to repo root so it can be used by `hg fix`...
r46195 pub async fn set_process_name(
&mut self,
name: impl AsRef<OsStr>,
) -> io::Result<()> {
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 let name_bytes = name.as_ref().as_bytes().to_owned();
self.client
.borrow_protocol_mut()
.send_command_with_args("setprocname", name_bytes)
.await
}
Yuya Nishihara
rust-chg: update name of the server process...
r45175
Yuya Nishihara
rust-chg: send client side umask to server...
r45174 /// Changes the umask of the server process.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn set_umask(&mut self, mask: u32) -> io::Result<()> {
let mut mask_bytes = BytesMut::with_capacity(mem::size_of_val(&mask));
mask_bytes.put_u32(mask);
self.client
.borrow_protocol_mut()
.send_command_with_args("setumask2", mask_bytes)
.await
}
Yuya Nishihara
rust-chg: send client side umask to server...
r45174
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 /// Runs the specified Mercurial command with cHg extension.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn run_command_chg(
&mut self,
handler: &mut impl SystemHandler,
Yuya Nishihara
rust-chg: leverage impl trait at argument position...
r45183 args: impl IntoIterator<Item = impl AsRef<OsStr>>,
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 ) -> io::Result<i32> {
runcommand::run_command(
self.client.borrow_protocol_mut(),
handler,
message::pack_args_os(args),
)
.await
}
Yuya Nishihara
rust-chg: add interface to run "validate" request...
r45171
/// Validates if the server can run Mercurial commands with the expected
/// configuration.
///
/// The `args` should contain early command arguments such as `--config`
/// and `-R`.
///
/// Client-side environment must be sent prior to this request, by
/// `set_current_dir()` and `set_env_vars_os()`.
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 pub async fn validate(
&mut self,
Yuya Nishihara
rust-chg: leverage impl trait at argument position...
r45183 args: impl IntoIterator<Item = impl AsRef<OsStr>>,
Yuya Nishihara
rust-chg: reimplement ChgClientExt as ChgClient wrapper...
r45236 ) -> io::Result<Vec<Instruction>> {
let data = self
.client
.borrow_protocol_mut()
.query_with_args("validate", message::pack_args_os(args))
.await?;
message::parse_instructions(data)
Yuya Nishihara
rust-chg: add interface to run "validate" request...
r45171 }
Yuya Nishihara
rust-chg: add Client extensions to run cHg-specific requests...
r40013 }