GithubHelp home page GithubHelp logo

Type annotations about nbclient HOT 16 CLOSED

jupyter avatar jupyter commented on August 30, 2024 2
Type annotations

from nbclient.

Comments (16)

MSeal avatar MSeal commented on August 30, 2024 1

I don't have any experience in type annotation, but I'm thinking that the Jupyter projects will need to exchange type definition, right? Like nbclient will probably need a definition of a KernelManager and a KernelClient I guess.

Doesn't need a type stub -- you can just import the class and use it in the annotation inline. The inline annotations actually read better for expectations.

For example:

from jupyter_client.managerabc import KernelManagerABC
from nbformat import NotebookNode
...

def __init__(self, nb: NotebookNode, km: KernelManagerABC=None, **kw):
  ...

works just fine

from nbclient.

davidbrochart avatar davidbrochart commented on August 30, 2024 1

Yes but traitlets validate type at runtime, it's not static type analysis.

from nbclient.

davidbrochart avatar davidbrochart commented on August 30, 2024

Should we use stubs files or add type annotations in the source code?
Should we use python>=3.6 type annotation syntax?

from nbclient.

MSeal avatar MSeal commented on August 30, 2024

Should we use stubs files or add type annotations in the source code?

I haven't used stubs much, just type annotations. I'm not sure how much benefit we'd get for using stubs? If you have more experience on that would love an opinion.

Should we use python>=3.6 type annotation syntax?

Yep

from nbclient.

choldgraf avatar choldgraf commented on August 30, 2024

Wait you mean we shouldn't interweave traitlets everywhere?

from nbclient.

choldgraf avatar choldgraf commented on August 30, 2024

(that is a joke, I think it's a good idea)

from nbclient.

davidbrochart avatar davidbrochart commented on August 30, 2024

I haven't used stubs much, just type annotations. I'm not sure how much benefit we'd get for using stubs? If you have more experience on that would love an opinion.

I don't have any experience in type annotation, but I'm thinking that the Jupyter projects will need to exchange type definition, right? Like nbclient will probably need a definition of a KernelManager and a KernelClient I guess.

from nbclient.

MSeal avatar MSeal commented on August 30, 2024

Wait you mean we shouldn't interweave traitlets everywhere?

I actually don't know how traitlets play with type annotations... that would be something to figure out I guess (joke aside)

from nbclient.

choldgraf avatar choldgraf commented on August 30, 2024

my (poor) understanding of traitlets is that one of the reasons it was developed was to allow you to type inputs, so I think (?) to some degree they replicate functionality

from nbclient.

MSeal avatar MSeal commented on August 30, 2024

They also provide a config interface for assignment from file / cml args.

from nbclient.

choldgraf avatar choldgraf commented on August 30, 2024

ok ok I apologize for throwing shade at traitlets :-)

from nbclient.

MSeal avatar MSeal commented on August 30, 2024

lol, I don't particularly like the traitlet model either as it uses less than ideal software practices to achieve (high complexity in tracing, 10+ class inheritance chains, makes init operations more complex, very obscure error message patterns when it fails, unexpected config inheritance patterns, etc) -- which I've been vocal about. I'd prefer removing traitlets from nbclient if we could.

I've left them when porting over because the file based config is used very very heavily in nbconvert and the users who use it like it a lot. So removing it from nbclient would require mapping that in nbconvert in the preprocessor layer... might be worth discussing doing before 1.0 of nbclient and 6.0 of nbconvert fully ship? Would be tough to choose.

from nbclient.

davidbrochart avatar davidbrochart commented on August 30, 2024

I guess if we just wanted the CLI part of traitlets, we could use click. But there's also the reactive part in traitlets (observing changes).

from nbclient.

choldgraf avatar choldgraf commented on August 30, 2024

(I'm a big fan of click)

from nbclient.

davidbrochart avatar davidbrochart commented on August 30, 2024

I have started to work on it in #83.

from nbclient.

davidbrochart avatar davidbrochart commented on August 30, 2024

Fixed in #83

from nbclient.

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.