Skip to content

cannot delete list directly del [x] #3878

Closed

Description

@key262yek

Feature

In CPython, they can delete a list in following manner

>>> x = 1
>>> del [x]

But, in RustPython we cannot.

>>> del [x]
SyntaxError: cannot delete list at line 1 column 1
del [x]
^

Related test is in Lib/test/test_syntax.py.

def test_assign_del(self):
        # ...
        self._check_error("del [*x,]", "cannot delete starred")    # Not "cannot delete list"

Python Documentation

Cannot find documentation exactly related this difference.

Activity

  1. changed the title [-]cannot delete 'list'[/-] [+]cannot delete list `del [x]`[/+] on Jul 14, 2022
  2. key262yek commented on Jul 14, 2022

    @key262yek
    ContributorAuthor

    related to #3879

  3. changed the title [-]cannot delete list `del [x]`[/-] [+]cannot delete list directly `del [x]`[/+] on Jul 14, 2022
  4. key262yek commented on Jul 14, 2022

    @key262yek
    ContributorAuthor

    I add match to List in compile_delete() in file compile/src/compile.rs

    ast::ExprKind::Tuple { elts, .. } | ast::ExprKind::List { elts, .. } => {
            for element in elts {
                self.compile_delete(element)?;
           }
    }

    pr #3879 includes the code changes.

  5. key262yek commented on Jul 20, 2022

    @key262yek
    ContributorAuthor

    It is resolved by pr #3879

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-compilerArea: compilerC-enhancementNew feature or requestz-ca-2022Tag to track contrubution-academy 2022

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions