ronantakizawa/codereview-bench huggingface dataset:
Repository: numpy/numpy
File: numpy/lib/_type_check_impl.py (Python)

Code before:
    Parameters
    ----------
    char : str
        Data type code.

    Returns
    -------
    out : str
        Description of the input data type code.

    See Also
    --------
    dtype

    Examples
    --------
    >>> import numpy as np
    >>> type(np.typename('S'))
    <class 'str'>
    >>> np.typename('S')
    'bytes'
    """
    try:
        return dtype(char).name
    except TypeError as e:
        raise TypeError(f"{char} does not represent a valid dtype") from None

#-----------------------------------------------------------------------------


#determine the "minimum common type" for a group of arrays.
array_type = [[_nx.float16, _nx.float32, _nx.float64, _nx.longdouble],
              [None, _nx.complex64, _nx.complex128, _nx.clongdouble]]
array_precision = {_nx.float16: 0,
                   _nx.float32: 1,
                   _nx.float64: 2,
                   _nx.longdouble: 3,
                   _nx.complex64: 1,
                   _nx.complex128: 2,
                   _nx.clongdouble: 3}


def _common_type_dispatcher(*arrays):
    return arrays


@array_function_dispatch(_common_type_dispatcher)
def common_type(*arrays):
    """
    Return a scalar type which is common to the input arrays.


Review comment (suggestion):
```suggestion
        raise TypeError(f"{char!r} does not represent a valid dtype") from None
```

some quotes might be nice

Code after:
                 'H': 'unsigned short',
                 'i': 'integer',
                 'I': 'unsigned integer',
                 'l': 'long integer',
                 'L': 'unsigned long integer',
                 'q': 'long long integer',
                 'Q': 'unsigned long long integer',
                 'f': 'single precision',
                 'd': 'double precision',
                 'g': 'long precision',
                 'F': 'complex single precision',
                 'D': 'complex double precision',
                 'G': 'complex long double precision',
                 'S': 'string',
                 'U': 'unicode',
                 'V': 'void',
                 'O': 'object'
                 }

@set_module('numpy')
def typename(char):
    """
    Return a description for the given data type code.

    Parameters
    ----------
    char : str
        Data type code.

    Returns
    -------
    out : str
        Description of the input data type code.

    See Also
    --------
    dtype

    Examples
    --------
    >>> import numpy as np
    >>> typechars = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q',
    ...              'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q']
    >>> for typechar in typechars:
    ...     print(typechar, ' : ', np.typename(typechar))
    ...
    S1  :  character
    ?  :  bool
    B  :  unsigned char
    D  :  complex double precision
    G  :  complex long double precision
Repository: numpy/numpy
File: numpy/lib/_type_check_impl.py (Python)

Code before:
    Return a description for the given data type code.

    Parameters
    ----------
    char : str
        Data type code.

    Returns
    -------
    out : str
        Description of the input data type code.

    See Also
    --------
    dtype

    Examples
    --------
    >>> import numpy as np
    >>> type(np.typename('S'))
    <class 'str'>
    >>> np.typename('S')
    'bytes'
    """
    try:
        return dtype(char).name
    except TypeError as e:
        raise TypeError(f"{char} does not represent a valid dtype") from None

#-----------------------------------------------------------------------------


#determine the "minimum common type" for a group of arrays.
array_type = [[_nx.float16, _nx.float32, _nx.float64, _nx.longdouble],
              [None, _nx.complex64, _nx.complex128, _nx.clongdouble]]
array_precision = {_nx.float16: 0,
                   _nx.float32: 1,
                   _nx.float64: 2,
                   _nx.longdouble: 3,
                   _nx.complex64: 1,
                   _nx.complex128: 2,
                   _nx.clongdouble: 3}


def _common_type_dispatcher(*arrays):
    return arrays


@array_function_dispatch(_common_type_dispatcher)
def common_type(*arrays):
    """

Review comment (suggestion):
This is backwards incompatible:

```py
>>> import numpy as np
>>> np.typename("F")
'complex single precision'
>>> np.dtype("F").name
'complex64'
```

Code after:
                 'B': 'unsigned char',
                 'h': 'short',
                 'H': 'unsigned short',
                 'i': 'integer',
                 'I': 'unsigned integer',
                 'l': 'long integer',
                 'L': 'unsigned long integer',
                 'q': 'long long integer',
                 'Q': 'unsigned long long integer',
                 'f': 'single precision',
                 'd': 'double precision',
                 'g': 'long precision',
                 'F': 'complex single precision',
                 'D': 'complex double precision',
                 'G': 'complex long double precision',
                 'S': 'string',
                 'U': 'unicode',
                 'V': 'void',
                 'O': 'object'
                 }

@set_module('numpy')
def typename(char):
    """
    Return a description for the given data type code.

    Parameters
    ----------
    char : str
        Data type code.

    Returns
    -------
    out : str
        Description of the input data type code.

    See Also
    --------
    dtype

    Examples
    --------
    >>> import numpy as np
    >>> typechars = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q',
    ...              'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q']
    >>> for typechar in typechars:
    ...     print(typechar, ' : ', np.typename(typechar))
    ...
    S1  :  character
    ?  :  bool
    B  :  unsigned char
Repository: numpy/numpy
File: numpy/lib/_type_check_impl.py (Python)

Code before:
        Data type code.

    Returns
    -------
    out : str
        Description of the input data type code.

    See Also
    --------
    dtype

    Examples
    --------
    >>> import numpy as np
    >>> np.typename('S')
    'bytes'
    >>> np.typename('F')
    'complex single precision'
    """
    # Preserve backward compatibility
    _legacy_mapping = {
            'F': 'complex single precision',
            'D': 'complex double precision',
            'G': 'complex long double precision',
            'S1': 'character',
    }

    if char in _legacy_mapping:
        return _legacy_mapping[char]

    try:
        return dtype(char).name
    except TypeError as e:
        raise TypeError(f"{char!r} does not represent a valid dtype") from None

#-----------------------------------------------------------------------------


#determine the "minimum common type" for a group of arrays.
array_type = [[_nx.float16, _nx.float32, _nx.float64, _nx.longdouble],
              [None, _nx.complex64, _nx.complex128, _nx.clongdouble]]
array_precision = {_nx.float16: 0,
                   _nx.float32: 1,
                   _nx.float64: 2,
                   _nx.longdouble: 3,
                   _nx.complex64: 1,
                   _nx.complex128: 2,
                   _nx.clongdouble: 3}


def _common_type_dispatcher(*arrays):

Review comment (suggestion):
You're missing a bunch of others. Almost all of the previous ones in the `_namefromtype` dict actually.

So I recommend reverting all code changes, and limiting this PR to the doc fixes

Code after:
                 'f': 'single precision',
                 'd': 'double precision',
                 'g': 'long precision',
                 'F': 'complex single precision',
                 'D': 'complex double precision',
                 'G': 'complex long double precision',
                 'S': 'string',
                 'U': 'unicode',
                 'V': 'void',
                 'O': 'object'
                 }

@set_module('numpy')
def typename(char):
    """
    Return a description for the given data type code.

    Parameters
    ----------
    char : str
        Data type code.

    Returns
    -------
    out : str
        Description of the input data type code.

    See Also
    --------
    dtype

    Examples
    --------
    >>> import numpy as np
    >>> typechars = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q',
    ...              'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q']
    >>> for typechar in typechars:
    ...     print(typechar, ' : ', np.typename(typechar))
    ...
    S1  :  character
    ?  :  bool
    B  :  unsigned char
    D  :  complex double precision
    G  :  complex long double precision
    F  :  complex single precision
    I  :  unsigned integer
    H  :  unsigned short
    L  :  unsigned long integer
    O  :  object
    Q  :  unsigned long long integer
    S  :  string
Repository: numpy/numpy
File: numpy/lib/_type_check_impl.py (Python)

Code before:
    G  :  complex long double precision
    F  :  complex single precision
    I  :  unsigned integer
    H  :  unsigned short
    L  :  unsigned long integer
    O  :  object
    Q  :  unsigned long long integer
    S  :  string
    U  :  unicode
    V  :  void
    b  :  signed char
    d  :  double precision
    g  :  long precision
    f  :  single precision
    i  :  integer
    h  :  short
    l  :  long integer
    q  :  long long integer

    """
    warnings.warn(
        "numpy.typename is deprecated. Use numpy.dtype.name instead.",
        DeprecationWarning,
        stacklevel=2,
    )
    return _namefromtype[char]

#-----------------------------------------------------------------------------


#determine the "minimum common type" for a group of arrays.
array_type = [[_nx.float16, _nx.float32, _nx.float64, _nx.longdouble],
              [None, _nx.complex64, _nx.complex128, _nx.clongdouble]]
array_precision = {_nx.float16: 0,
                   _nx.float32: 1,
                   _nx.float64: 2,
                   _nx.longdouble: 3,
                   _nx.complex64: 1,
                   _nx.complex128: 2,
                   _nx.clongdouble: 3}


def _common_type_dispatcher(*arrays):
    return arrays


@array_function_dispatch(_common_type_dispatcher)
def common_type(*arrays):
    """
    Return a scalar type which is common to the input arrays.


Review comment (suggestion):
```suggestion
	# Deprecated in NumPy 2.5, 2026-02-03
    warnings.warn(
        "numpy.typename is deprecated. Use numpy.dtype.name instead.",
        DeprecationWarning,
        stacklevel=2,
    )
```

Code after:
    G  :  complex long double precision
    F  :  complex single precision
    I  :  unsigned integer
    H  :  unsigned short
    L  :  unsigned long integer
    O  :  object
    Q  :  unsigned long long integer
    S  :  string
    U  :  unicode
    V  :  void
    b  :  signed char
    d  :  double precision
    g  :  long precision
    f  :  single precision
    i  :  integer
    h  :  short
    l  :  long integer
    q  :  long long integer

    """
    # Deprecated in NumPy 2.5, 2026-02-03
    warnings.warn(
        "numpy.typename is deprecated. Use numpy.dtype.name instead.",
        DeprecationWarning,
        stacklevel=2
    )
    return _namefromtype[char]

#-----------------------------------------------------------------------------


#determine the "minimum common type" for a group of arrays.
array_type = [[_nx.float16, _nx.float32, _nx.float64, _nx.longdouble],
              [None, _nx.complex64, _nx.complex128, _nx.clongdouble]]
array_precision = {_nx.float16: 0,
                   _nx.float32: 1,
                   _nx.float64: 2,
                   _nx.longdouble: 3,
                   _nx.complex64: 1,
                   _nx.complex128: 2,
                   _nx.clongdouble: 3}


def _common_type_dispatcher(*arrays):
    return arrays


@array_function_dispatch(_common_type_dispatcher)
def common_type(*arrays):
    """
    Return a scalar type which is common to the input arrays.
Repository: numpy/numpy
File: numpy/lib/_type_check_impl.py (Python)

Code before:
    D  :  complex double precision
    G  :  complex long double precision
    F  :  complex single precision
    I  :  unsigned integer
    H  :  unsigned short
    L  :  unsigned long integer
    O  :  object
    Q  :  unsigned long long integer
    S  :  string
    U  :  unicode
    V  :  void
    b  :  signed char
    d  :  double precision
    g  :  long precision
    f  :  single precision
    i  :  integer
    h  :  short
    l  :  long integer
    q  :  long long integer

    """
    # Deprecated in NumPy 2.5, 2026-02-03
    warnings.warn(
        "numpy.typename is deprecated. Use numpy.dtype.name instead.",
        DeprecationWarning,
        skip_file_prefixes=(os.path.dirname(__file__),),
        stacklevel=2,
    )
    return _namefromtype[char]

#-----------------------------------------------------------------------------


#determine the "minimum common type" for a group of arrays.
array_type = [[_nx.float16, _nx.float32, _nx.float64, _nx.longdouble],
              [None, _nx.complex64, _nx.complex128, _nx.clongdouble]]
array_precision = {_nx.float16: 0,
                   _nx.float32: 1,
                   _nx.float64: 2,
                   _nx.longdouble: 3,
                   _nx.complex64: 1,
                   _nx.complex128: 2,
                   _nx.clongdouble: 3}


def _common_type_dispatcher(*arrays):
    return arrays


@array_function_dispatch(_common_type_dispatcher)
def common_type(*arrays):

Review comment (suggestion):
```suggestion
        skip_file_prefixes=(os.path.dirname(__file__)),
```

Code after:
    G  :  complex long double precision
    F  :  complex single precision
    I  :  unsigned integer
    H  :  unsigned short
    L  :  unsigned long integer
    O  :  object
    Q  :  unsigned long long integer
    S  :  string
    U  :  unicode
    V  :  void
    b  :  signed char
    d  :  double precision
    g  :  long precision
    f  :  single precision
    i  :  integer
    h  :  short
    l  :  long integer
    q  :  long long integer

    """
    # Deprecated in NumPy 2.5, 2026-02-03
    warnings.warn(
        "numpy.typename is deprecated. Use numpy.dtype.name instead.",
        DeprecationWarning,
        stacklevel=2
    )
    return _namefromtype[char]

#-----------------------------------------------------------------------------


#determine the "minimum common type" for a group of arrays.
array_type = [[_nx.float16, _nx.float32, _nx.float64, _nx.longdouble],
              [None, _nx.complex64, _nx.complex128, _nx.clongdouble]]
array_precision = {_nx.float16: 0,
                   _nx.float32: 1,
                   _nx.float64: 2,
                   _nx.longdouble: 3,
                   _nx.complex64: 1,
                   _nx.complex128: 2,
                   _nx.clongdouble: 3}


def _common_type_dispatcher(*arrays):
    return arrays


@array_function_dispatch(_common_type_dispatcher)
def common_type(*arrays):
    """
    Return a scalar type which is common to the input arrays.
Repository: numpy/numpy
File: numpy/_build_utils/tempita/_tempita.py (Python)

Code before:

class bunch(dict):
    def __init__(self, **kw):
        for name, value in kw.items():
            setattr(self, name, value)

    def __setattr__(self, name, value):
        self[name] = value

    def __getattr__(self, name):
        try:
            return self[name]
        except KeyError:
            raise AttributeError(name)

    def __getitem__(self, key):
        if "default" in self:
            try:
                return dict.__getitem__(self, key)
            except KeyError:
                return dict.__getitem__(self, "default")
        else:
            return dict.__getitem__(self, key)

    def __repr__(self):
        items_str = " ".join([f"{k}={v!r}" for k, v in sorted(self.items())],)
        return f"<{self.__class__.__name__} {items_str}>"


class TemplateDef:
    def __init__(
        self, template, func_name, func_signature, body, ns, pos, bound_self=None
    ):
        self._template = template
        self._func_name = func_name
        self._func_signature = func_signature
        self._body = body
        self._ns = ns
        self._pos = pos
        self._bound_self = bound_self

    def __repr__(self):
        return (f"<tempita function {self._func_name}({self._func_signature}) at "
                f"{self._template.name}:{self._pos}>")

    def __str__(self):
        return self()

    def __call__(self, *args, **kw):
        values = self._parse_signature(args, kw)
        ns = self._ns.copy()

Review comment (suggestion):
```suggestion
        items_str = " ".join([f"{k}={v!r}" for k, v in sorted(self.items())])
```

Code after:

class bunch(dict):
    def __init__(self, **kw):
        for name, value in kw.items():
            setattr(self, name, value)

    def __setattr__(self, name, value):
        self[name] = value

    def __getattr__(self, name):
        try:
            return self[name]
        except KeyError:
            raise AttributeError(name)

    def __getitem__(self, key):
        if "default" in self:
            try:
                return dict.__getitem__(self, key)
            except KeyError:
                return dict.__getitem__(self, "default")
        else:
            return dict.__getitem__(self, key)

    def __repr__(self):
        items_str = " ".join([f"{k}={v!r}" for k, v in sorted(self.items())])
        return f"<{self.__class__.__name__} {items_str}>"


class TemplateDef:
    def __init__(
        self, template, func_name, func_signature, body, ns, pos, bound_self=None
    ):
        self._template = template
        self._func_name = func_name
        self._func_signature = func_signature
        self._body = body
        self._ns = ns
        self._pos = pos
        self._bound_self = bound_self

    def __repr__(self):
        return (f"<tempita function {self._func_name}({self._func_signature}) at "
                f"{self._template.name}:{self._pos}>")

    def __str__(self):
        return self()

    def __call__(self, *args, **kw):
        values = self._parse_signature(args, kw)
        ns = self._ns.copy()
Repository: nushell/nushell
File: crates/nu-command/tests/commands/run_external.rs (Rust)

Code before:
                ^echo "\"abcd"
            "#
        ));

        assert_eq!(actual.out, r#""abcd"#);
    })
}

#[test]
fn external_command_not_expand_tilde_with_quotes() {
    Playground::setup(
        "external command not expand tilde with quotes",
        |dirs, _| {
            let actual = nu!(cwd: dirs.test(), pipeline(r#"nu --testbin nonu "~""#));
            assert_eq!(actual.out, r#"~"#);
        },
    )
}

#[cfg(windows)]
#[test]
fn failed_command_with_semicolon_will_not_execute_following_cmds_windows() {
    Playground::setup("external failed command with semicolon", |dirs, _| {
        let actual = nu!(
            cwd: dirs.test(), pipeline(
            r#"
                ^cargo asdf; echo done
            "#
        ));

        assert!(!actual.out.contains("done"));
    })
}

#[cfg(windows)]
#[test]
fn can_run_batch_files() {
    use nu_test_support::fs::Stub::FileWithContent;
    Playground::setup("run a Windows batch file", |dirs, sandbox| {
        sandbox.with_files(vec![FileWithContent(
            "foo.cmd",
            r#"
                @echo off
                echo Hello World
            "#,
        )]);

        let actual = nu!(cwd: dirs.test(), pipeline("foo.cmd"));
        assert!(actual.out.contains("Hello World"));
    });
}

Review comment (refactor):
Thanks for adding the testing utility!

Let's measure the `deadbeef` with your new testbin here :)

Code after:
                ^echo "\"abcd"
            "#
        ));

        assert_eq!(actual.out, r#""abcd"#);
    })
}

#[test]
fn external_command_not_expand_tilde_with_quotes() {
    Playground::setup(
        "external command not expand tilde with quotes",
        |dirs, _| {
            let actual = nu!(cwd: dirs.test(), pipeline(r#"nu --testbin nonu "~""#));
            assert_eq!(actual.out, r#"~"#);
        },
    )
}

#[test]
fn external_command_receives_raw_binary_data() {
    Playground::setup("external command receives raw binary data", |dirs, _| {
        let actual =
            nu!(cwd: dirs.test(), pipeline(r#"0x[deadbeef] | nu --testbin input_bytes_length"#));
        assert_eq!(actual.out, r#"4"#);
    })
}

#[cfg(windows)]
#[test]
fn failed_command_with_semicolon_will_not_execute_following_cmds_windows() {
    Playground::setup("external failed command with semicolon", |dirs, _| {
        let actual = nu!(
            cwd: dirs.test(), pipeline(
            r#"
                ^cargo asdf; echo done
            "#
        ));

        assert!(!actual.out.contains("done"));
    })
}

#[cfg(windows)]
#[test]
fn can_run_batch_files() {
    use nu_test_support::fs::Stub::FileWithContent;
    Playground::setup("run a Windows batch file", |dirs, sandbox| {
        sandbox.with_files(vec![FileWithContent(
            "foo.cmd",
            r#"
Repository: nushell/nushell
File: crates/nu-cli/src/repl.rs (Rust)

Code before:
        assert_eq!(expected, actual);
    }

    #[test]
    fn escape_vscode_linefeed_test() {
        let input = "now\nis";
        let expected = r#"now\x0Ais"#;
        let actual = escape_special_vscode_bytes(input);
        assert_eq!(expected, actual);
    }

    #[test]
    fn escape_vscode_tab_null_cr_test() {
        let input = "now\t\0\ris";
        let expected = r#"now\x09\x00\x0Dis"#;
        let actual = escape_special_vscode_bytes(input);
        assert_eq!(expected, actual);
    }

    #[test]
    fn escape_vscode_multibyte_ok() {
        let input = "now🍪is";
        let expected = format!("{}", "now\u{F0}\u{9F}\u{8D}\u{AA}is".escape_unicode());
        let actual = format!("{}", escape_special_vscode_bytes(input).escape_unicode());

        assert_eq!(expected, actual);
    }
}


Review comment (security):
The expected should be `input` here, as there are no ASCII control or `;``\` in the string. The `escape_unicode()` that is tacked on to the call in `actual` will turn it into the string

```suggestion
        let actual = escape_special_vscode_bytes(input);

        assert_eq!(input, actual);
```

Code after:
        let actual = escape_special_vscode_bytes(input).unwrap();
        assert_eq!(expected, actual);
    }

    #[test]
    fn escape_vscode_backslash_test() {
        let input = r#"now\is"#;
        let expected = r#"now\\is"#;
        let actual = escape_special_vscode_bytes(input).unwrap();
        assert_eq!(expected, actual);
    }

    #[test]
    fn escape_vscode_linefeed_test() {
        let input = "now\nis";
        let expected = r#"now\x0Ais"#;
        let actual = escape_special_vscode_bytes(input).unwrap();
        assert_eq!(expected, actual);
    }

    #[test]
    fn escape_vscode_tab_null_cr_test() {
        let input = "now\t\0\ris";
        let expected = r#"now\x09\x00\x0Dis"#;
        let actual = escape_special_vscode_bytes(input).unwrap();
        assert_eq!(expected, actual);
    }

    #[test]
    fn escape_vscode_multibyte_ok() {
        let input = "now🍪is";
        let actual = escape_special_vscode_bytes(input).unwrap();
        assert_eq!(input, actual);
    }
}