kotlin-jupyter: Cannot OptIn to an experimental annotation class

A minimal repro:

import kotlin.time.*

@ExperimentalTime
val res = runBlocking {
    val mark = TimeSource.Monotonic.markNow()
    delay(300)
    mark.elapsedNow()
}

println(res)

Image for clarification: image

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Does this compiles for you?

@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
import kotlin.time.*
import kotlinx.coroutines.*
            
@OptIn(ExperimentalTime::class)
val res = runBlocking {
    val mark = kotlin.time.TimeSource.Monotonic.markNow()
    delay(3)
    mark.elapsedNow()
}
res

It seems that actual problem for you here is this issue

@frankgerhardt sorry for delay, I haven’t mentioned your message… For now it works like this.

  1. Restart kernel and execute:
@file:CompilerArgs("-Xopt-in=kotlin.RequiresOptIn")

Note that it should be the first executed cell in the notebook session.

  1. Then execute the code you have mentioned, but with a minor change:
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2")
import kotlin.time.*
import kotlinx.coroutines.*
            
@OptIn(ExperimentalTime::class)
val res = runBlocking {
    val mark = kotlin.time.TimeSource.Monotonic.markNow()
    delay(3)
    mark.elapsedNow()
}
@OptIn(ExperimentalTime::class)
res

Ok, the last problem left here (and the one that could be resolved) is passing free compiler args. It required some fixes in REPL, will get back to you once it will be merged and I’ll add this functionality.

The easiest way to resolve such issues is to set JUPYTER_PATH env. variable: https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs In your case it will be %APPDATA%/Python/share/jupyter

You have this problem not because of Windows, but because of

Defaulting to user installation because normal site-packages is not writeable

In user mode paths are different, and Jupyter can’t find the installed kernel 😦

Maybe another fix is to run pip install in cmd with administrative rights.

I’m using 0.8.3 basically pip installation didn’t work for me (notebook wasn’t appearing, tested both on windows & linux), so I just cloned and ran install task: git clone https://github.com/Kotlin/kotlin-jupyter.git && cd kotlin-jupyter && ./gradlew install

Actually, compiles for me, but I’ll recheck and maybe add a possibility of passing compiler arguments (via magics)