Giter VIP home page Giter VIP logo

Comments (2)

krassowski avatar krassowski commented on May 18, 2024

The current workaround of replacing line magics with "pass" (for Python) and skipping cell magics works but has a drawback: the imported cell/line magics are not included in the virtual document, thus there are false-positive linter messages like "X is imported but unused".

A more robust workaround would add a function call for the magic, reflecting what IPython would do (after initial parsing to determine the magic to be used) - thus the magic would be used in the code.

Ideally, we would allow the user to define custom regular expressions, for example parsing R-magic:

%%R -i input_variable -o output_variable
some R code

into

# noqa
output_variable = R(input_variable)

while this would not work if executed, this is not the goal here - what we want is that the linter registers the that

  1. R magic was used (though R magic, in particular, does not require importing but is rather loaded via another magic)
  2. a new variable (output_variable) of unknown type was registered in the namespace
  3. the input_variable was used.

An initial set of rules (sensible defaults), per language, could be defined in the settings, allowing the user to disable any or all of them and add their own regular expression based rules.

Notes:

  • In an alternative reality, we could ask linters to respect all the fancy features introduced by interactive kernels, but there will always be a gap between the introduction of new magic to a specific kernel and all the possible linters picking up on that:
    • for example, LSP for Python depends on over a dozen different specialized linters, many of which may consider the ipython feature requests to be too specific for their scope.
    • on the other hand, the LSP for R has much, much slower rate of development, possibly because most of the casual R users, while excelling in statistical programming are not programmers familiar with advanced general programming aspects.
  • there are some transpiling solutions (IPython → plain python file), which we could use as a reference, to avoid re-inventing a wheel

Update: actually, using noqa is not needed as we can simply ignore the result of inspection for these lines. For simplicity, the regular expressions should return a single line as otherwise, the mapping between the virtual document and notebook gets more tricky.

from jupyterlab-lsp.

krassowski avatar krassowski commented on May 18, 2024

Current implementation demonstrated and explained in examples/Magics_and_rpy2.ipynb.

from jupyterlab-lsp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.