Skip to content

allow different types of lists to be appended#8157

Merged
fdncred merged 2 commits intonushell:mainfrom
fdncred:allow_list_assignment
Feb 22, 2023
Merged

allow different types of lists to be appended#8157
fdncred merged 2 commits intonushell:mainfrom
fdncred:allow_list_assignment

Conversation

@fdncred
Copy link
Copy Markdown
Contributor

@fdncred fdncred commented Feb 21, 2023

Description

closes #8153

This PR allows different types of lists, like list<string> and list<any> to be appended with the ++= operator.

Before

mut args = [ hello ("hello" | path join world)]
$args ++= [ foo bar ]
Error: nu::parser::type_mismatch (link)

  × Type mismatch during operation.
   ╭─[entry #2:1:1]
 1 │ $args ++= [ foo bar ]
   ·           ─────┬─────
   ·                ╰── expected list<any>, found list<string>
   ╰────

After

mut args = [ hello ("hello" | path join world)]
$args ++= [ foo bar ]
$args
╭───┬─────────────╮
│ 0 │ hello       │
│ 1 │ hello\world │
│ 2 │ foo         │
│ 3 │ bar         │
╰───┴─────────────╯

User-Facing Changes

(List of all changes that impact the user experience here. This helps us keep track of breaking changes.)

Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace to check that all tests pass

After Submitting

If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.

@fdncred fdncred changed the title allow different types of listed to be appended allow different types of lists to be appended Feb 21, 2023
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 21, 2023

Codecov Report

Merging #8157 (f910346) into main (e89866b) will increase coverage by 0.37%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8157      +/-   ##
==========================================
+ Coverage   54.23%   54.61%   +0.37%     
==========================================
  Files         608      608              
  Lines       99012    99013       +1     
==========================================
+ Hits        53702    54074     +372     
+ Misses      45310    44939     -371     
Impacted Files Coverage Δ
crates/nu-parser/src/type_check.rs 25.43% <0.00%> (-0.06%) ⬇️
crates/nu-color-config/src/style_computer.rs 80.76% <0.00%> (-0.55%) ⬇️
crates/nu-color-config/src/nu_style.rs 80.22% <0.00%> (+70.91%) ⬆️

@fdncred fdncred added this pull request to the merge queue Feb 22, 2023
Merged via the queue into nushell:main with commit e761954 Feb 22, 2023
@fdncred fdncred deleted the allow_list_assignment branch February 22, 2023 12:55
@glcraft
Copy link
Copy Markdown

glcraft commented Feb 22, 2023

I just test this PR on my machine, it works perfectly, nice job 👍

@sholderbach sholderbach added the notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes label Mar 14, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Mar 15, 2023
Themes of this release / New features
 - Reworked aliases (Breaking changes!) (kubouch)
   Aliases have been a constant source of panics and growing code complexity as
   a result of trying to patch the panics. In this release, we re-implement
   aliases from scratch. Instead of replacing spans of expressions, aliases are
   implemented as another type of command, quite like extern is used to
   implement known externals. Alias is a command that wraps another command
   call. As a result, in some cases, aliases do not behave exactly the same as
   before. Here are the key facts:
    - Alias can only alias another command call. For example, alias la = ls -a
    works, but the following does not:
       - alias foo = "foo"
            "foo" is not a command call, use alias foo = echo "foo" instead
       - alias lsn = (ls | sort-by type name -i)
            subexpression is not a command call, use a custom command instead
     - Alias cannot alias command named the same as the alias. E.g., alias
     ls = ls -a is not possible currently, and gives an unhelpful error message.
     We plan to fix this as soon as possible and in the future we aim for this
     to work.
     - Some parser keywords are not allowed to be aliased. Currently, overlay
     commands can be aliased but the other parser keywords can not. We can add
     support for aliasing more parser keywords in the future.

If some of the above is too limiting for you, the old aliases are still
unchanged and available as old-alias. Just change alias to old-alias and it
should work the same as before. If there are no more problems with the new
alias implementation, and we manage to iron out the recursive alias issue,
we will remove old-alias in the next release, otherwise, we'll keep it around
longer.

 - More consistent timestamp handling (bobhy)
   Simplified conversion between Nushell date type and unix timestamps (#8244).

Nushell now standardizes on representing a Unix timestamp as a number of
nanoseconds relative to the unix epoch 1970-01-01 00:00:00 +0000 (UTC).
Since the timestamp is stored in a (64 bit signed) Nushell int type, this
limits the range of dates that can be represented to approximately 21-sep-1677
through 11-apr-2262.

In prior versions, Nushell attempted to extend the range of representable dates
by allowing multiple resolutions of timestamps (seconds, milliseconds as well
as nanoseconds) to be stored and relied on arbitrary range check heuristics to
disambiguate the value intended. However, there were bugs in the checks and
incorrect results could be produced.

With this change <int> | into datetime assumes the input is a number of
nanoseconds and can never produce a date outside this range.
The timestamp epoch is the standard unix epoch. Note the timezone is UTC/GMT.

<datetime> | into int can now produce an error if the input is outside the
supported range.

And finally, although not strictly required by the above fix,
<date> | date to-record and <date> | date to-table now have a nanosecond field
containing the subsecond residue of the input value (however it was produced).

 - New XML format (NotLebedev)

 New format for xml data created and accepted by from xml and to xml commands
 (#7947).

Commands from xml and to xml now use format where each xml entry is represented
by a single {tag: <tag name> attributes: <tag attributes> content:
[<child entries>]} record. Special xml entries also use this record, replacing
irrelevant fields with null for easier use.

Creating a little html page. In case of to xml one can deviate from rigid
structure and omit empty fields of records.

 - New additions to $nu (StevenDoesStuffs, amtoine)
 The builtin $nu variable now contains new entries:
  - is-interactive: Nushell was launched in interactive mode
  - is-login: Nushell was launched in login mode
  - startup_time: Nushell's startup time

 - Reworked http subcommands (jaudiger)

The http command now has more subcommands and existing subcommands have been
reworked.

Make sure to browse the help messages of these commands. They contain fully
functional examples thanks to pointing at www.example.com.

 - Breaking changes

    - Alias changes, see above
    - env command has been removed, use $env instead
    (nushell/nushell#8185)
    - str trim no longer has --all, --both, and --format flags. str replace
    should be an adequate replacement; please let us know if it is not (#8205)
    - The changes to timestamp handling noted above (#8244) can require code
    changes to existing scripts:
      - Saved data containing the results of an old datetime-to-timestamp
      conversion will not deserialize correctly when read back by the current
      version of Nushell. In general, Nushell will produce incorrect datetime
      values without noting an error.
      - <int> | into datetime now assumes nanosecond scaling for all timestamps.
      You must ensure all timestamps computed by your script or retrieved from
      external sources are scaled appropriately.
      - <date> | into int can now fail, as noted above. You cannot rely on this
      operation to persist a arbitrary date.
    - The change to from xml and to xml commands noted above (#7947) will
    require to update scripts relying on old output/input format.
    - mkdir, cp, mv and rm return nothing. Errors and actions with --verbose
    flag are printed to stderr instead (#8014).
    - Plugin authors relying on nu_protocol::Value may need to update their
    code to account for a change to Value::Error (#8375    )
    - Different types of lists can now be appended. This can break scripts that
    were relying on the stricter behavior
    (nushell/nushell#8157)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cant append list<type> in list<any> using ++= operator

3 participants