Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 04 22:11
    evhub closed #386
  • May 04 22:11
    evhub commented #386
  • May 04 22:09
    evhub milestoned #386
  • May 04 22:08
    evhub labeled #386
  • May 04 08:28
    evhub closed #572
  • May 04 07:57
    evhub edited #572
  • May 04 07:56
    evhub milestoned #572
  • May 04 07:56
    evhub labeled #572
  • May 04 07:56
    evhub labeled #572
  • May 04 07:56
    evhub labeled #572
  • May 04 07:56
    evhub opened #572
  • May 04 00:44
    evhub closed #519
  • May 04 00:44
    evhub commented #519
  • May 04 00:44
    evhub labeled #519
  • May 03 23:53
    evhub milestoned #519
  • May 03 23:53
    evhub commented #519
  • Apr 30 04:54
    evhub closed #571
  • Apr 30 04:54
    evhub commented #571
  • Apr 30 04:54
    evhub labeled #571
  • Apr 30 04:19
    evhub commented #571
Thurston Sexton
@tbsexton
I should clarify, a pattern-matching __fmap__

the other way is to have to manually specify for every function whether it uses the edge or node view. the problem is, I would like to write them in terms of straight np.array or jax.numpy.array objects, and having to add a

@addpattern(myfunc)
def myfunc(g is graph)=
    myfunc(g.adjacency)

seems like a lot of extra boilerplate...

Cristhian Motoche
@CristhianMotoche

Hello! I'm just starting with coconut and I'm integrating it with mypy. I created a simple hello world example

"hello world" |> print

and I tried to compile it integrating it with mypy:

coconut run.coco --mypy

but I'm getting this odd error:

Compiling         run.coco ...
Compiled to       run.py .
$HOME/.coconut_stubs/__coconut__.pyi:81: error: Module has no attribute "abc"
Found 1 error in 1 file (checked 1 source file)
Exiting due to MyPy error.

What could be the cause of this error?

FYI, I'm using a virtual environment and Python 3.7.

Evan Hubinger
@evhub
@CristhianMotoche It looks like mypy is getting mad at Coconut using collections.abc, which is strange because it be available on Python 3.7. First, just try uninstalling coconut and reinstalling the latest dev version by running pip install --upgrade coconut-develop[mypy] and see if that fixes the issue. If not, try running coconut run.coco --target sys --mypy instead, which should tell mypy to check according to the current Python version.
Cristhian Motoche
@CristhianMotoche
Thanks for the response @evhub . I tried both options but they didn't work. Maybe the verbose output of the compiler can help to identify the issue:
(coconut-sample-fvM68vJh-py3.7) ➜  coconut-sample git:(master) ✗ coconut run.coco  --verbose --mypy
Using Cython cPyparsing v2.4.5.
Parsed args: Namespace(argv=None, code=None, dest=None, display=False, documentation=False, force=False, history_file=None, interact=False, jobs=None, jupyter=None, keep_lines=False, line_numbers=False, minify=False, mypy=[], no_tco=False, no_write=False, package=False, quiet=False, recursion_limit=None, run=False, source='run.coco', standalone=False, strict=False, style=None, target=None, tutorial=False, verbose=True, watch=False)
Compiler args: {'target': '', 'strict': False, 'minify': False, 'line_numbers': False, 'keep_lines': False, 'no_tco': False}
MyPy args: ['--python-version', '3.7', '--warn-incomplete-stub', '--warn-redundant-casts', '--warn-return-any', '--warn-unused-configs', '--show-error-context']
Hash args: {'VERSION_STR': '1.4.3 [Ernest Scribbler]', 'reduce_args': ('', False, False, False, False, False), 'package_level': 0}
Compiling         $HOME/Documents/code/Coconut/coconut-sample/run.coco ...
Hash args: {'VERSION_STR': '1.4.3 [Ernest Scribbler]', 'reduce_args': ('', False, False, False, False, False), 'package_level': 0}
Time while parsing: 1.245418 seconds
Packrat parsing stats: 494 hits; 6419 misses
Compiled to       $HOME/Documents/code/Coconut/coconut-sample/run.py .
Traceback (most recent call last):
  File "$HOME/.cache/pypoetry/virtualenvs/coconut-sample-fvM68vJh-py3.7/lib/python3.7/site-packages/coconut/command/util.py", line 300, in symlink
    os.symlink(link_to, link_from, target_is_directory=True)
FileExistsError: [Errno 17] File exists: '$HOME/.cache/pypoetry/virtualenvs/coconut-sample-fvM68vJh-py3.7/lib/python3.7/site-packages/coconut/stubs' -> '$HOME/.coconut_stubs'
MYPYPATH = $HOME/.coconut_stubs
> mypy $HOME/Documents/code/Coconut/coconut-sample/run.py --python-version 3.7 --warn-incomplete-stub --warn-redundant-casts --warn-return-any --warn-unused-configs --show-error-context
run.py:16: note: In module imported here:
$HOME/.coconut_stubs/__coconut__.pyi: note: In class "_coconut":
$HOME/.coconut_stubs/__coconut__.pyi:81: error: Module has no attribute "abc"
Found 1 error in 1 file (checked 1 source file)
Exiting due to MyPy error.
Eric Anderson
@Nexus6

What a coincidence, I ran face-first into this same issue just last night. I too am in a venv on Linux, but using the Python 3.8.5 from the Manjaro repos. Below are some details of the environment, edited for clarity:
$ coconut -v
Coconut: Version 1.4.3 [Ernest Scribbler] running on Python 3.8.5
$ python
Python 3.8.5 (default, Sep 5 2020, 10:50:12)
[GCC 10.2.0] on linux

import collections.abc
abc = collections.abc
import sys
sys.version_info
sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)
sys.version_info > (3,3)
True
sys.version_info < (3,3)
False
$ mypy -V
mypy 0.790
$ coconut -t 38 -j 4 -k --no-tco --force . --mypy
Compiling main.coco ...
Compiled to main.py .

$HOME/.coconut_stubs/coconut.pyi:99: error: Module has no attribute "abc"

It would appear that the mypy error is happening on the "abc = collections.abc" assignment in coconut.pyi which is strange since that works fine in the repl.

Ugh, apologies for the formatting fail. Forgot to mention, using "coconut -t sys ..." did not change the behavior that we're seeing for me.
Evan Hubinger
@evhub
@CristhianMotoche @Nexus6 I think this is an error symlinking the stub file dir—could one of you raise an issue for this?
Eric Anderson
@Nexus6
I checked and on my system ~/.coconut_stubs was a symlink to another Coconut environment, but the wrong one. I don't know how that happened. Nevertheless, after attempting to correct it by reconstituting it to a symlink to my current project, I now have lrwxrwxrwx 1 me me 59 Nov 3 15:46 $HOME/.coconut_stubs -> $HOME/.local/lib/python3.8/site-packages/coconut/stubs and yet I'm still getting, on compile, $HOME/.coconut_stubs/__coconut__.pyi:81: error: Module has no attribute "abc" with no other changes.
Fabien Bourgeois
@Yakulu
@evhub Are pipeline optimizations still here ? The last example compiles to (print)((sq)((_coconut.operator.add)(*(1, 2)))) for me
Instead of print(sq(operator.add(1, 2)))
That said, perhaps there is no performance hit doing like that.
Evan Hubinger
@evhub
@Yakulu Pipeline optimization is what's removing the partial application object. There shouldn't be any meaningful performance hit from any of the other stuff.
Fabien Bourgeois
@Yakulu
@evhub Thanks for the explanation
Jeff P
@HikaGenji
Hello, I am new to coconut, been going through the docs and couldn't find guidance on how to package coconut code as module. What is the best practice to package and reuse coconut module ?
Evan Hubinger
@evhub
@HikaGenji Just compile to Python and package the compiled Python however you normally would for a Python module. See: https://coconut.readthedocs.io/en/master/FAQ.html#how-do-i-release-a-coconut-package-on-pypi
Jeff P
@HikaGenji
@evhub thx, and apologies for missing this
Bruce Eckel
@BruceEckel

From https://coconut.readthedocs.io/en/master/DOCS.html#reduce:
reduce(function, iterable[, initializer])
Used in your example:

product = reduce$(*)
range(1, 10) |> product |> print

In this case, the second argument, iterable, is supplied by range(1,10). How would I add an initializer into this example? thanks.

Evan Hubinger
@evhub
@BruceEckel You can do:
range(1, 10) |> reduce$((*), ?, initializer) |> print
OldIronHorse
@OldIronHorse
Hi. I'm working my way through the classic "99 Problems" as I get to grips with Coconut and I've run into what looks like an inconsistency with the lazy iterator slicing. In order to make my implementation of "split" work I have to wrap the iterator with "reiterable" but a very similar looking implementation of "rotate" works just fine without it.
Here's the code:
def split(n, ls) = 
    ls = reiterable(ls)
    (ls$[:n], ls$[n:])
def rotate(n, ls) = ls$[n:] :: ls$[:n]
OldIronHorse
@OldIronHorse
So I'm wondering what I've misunderstood here.
OldIronHorse
@OldIronHorse
Well, this is embarrassing: my test case for "rotate" wasn't passing a lazy list.
Now that it is the reiterable wrapper is required and consistency is restored.
Evan Hubinger
@evhub
@OldIronHorse Yep, that's right—reiterable is required when working with iterators (e.g. lazy lists), but not when working with iterables (e.g. lists or tuples).
Michael Tingley
@michaeltingley

Hi there! I'm new to Coconut (amazing project, by the way!!), and I was wondering if there's a way to enable --mypy type checking in a Jupyter kernel. I tried starting the kernel with python -m coconut.icoconut --mypy, but this gives me an error saying basically that --mypy is not a valid argument. I'm wondering if there's a way to forward along --mypy to the underlying Coconut runtime?

Or alternatively (more jankily), is there a way to enable mypy (e.g. some magic constant I can set to True) within the already-running Coconut runtime in order to have it enable mypy type checking?

Thank you!

Evan Hubinger
@evhub

@michaeltingley There's currently no way to do this using the Coconut Jupyter kernel, but you can do it with the Coconut Jupyter magic if you do %load_ext coconut and then:

%%coconut --mypy
x: str = 1

which should give you an error. Also, I should note that calling coconut.icoconut directly is generally not what you want to be doing; you should probably default to coconut --jupyter console or coconut --jupyter notebook instead.

Michael Tingley
@michaeltingley
This is very cool! Unfortunately, I can't get it to work. I'm getting the error variable names cannot start with reserved prefix _coconut. Here's a screenshot. Let me know if you have any ideas!

(There are also a few other warnings, which you can see in that image:

CoconutSyntaxWarning: unnecessary from __future__ import (Coconut does these automatically) (line 3)
  from __future__ import print_function, absolute_import, unicode_literals, division
CoconutSyntaxError: variable names cannot start with reserved prefix _coconut (line 4)
  import sys as _coconut_sys
                ^
  File "<string>", line unknown
SyntaxError: variable names cannot start with reserved prefix _coconut
  import sys as _coconut_sys

)

Evan Hubinger
@evhub
@michaeltingley Ah, the problem is you're using %%coconut from inside a Coconut kernel, which doesn't work since Coconut ends up trying to compile that code twice, once by %%coconut and once by the kernel itself. You should try using %%coconut inside of a Python kernel instead.
Michael Tingley
@michaeltingley
@evhub Oh, OK, thanks. So there's no way to get mypy enforcement inside a Coconut kernel I guess? Thanks anyways for the help :)
Evan Hubinger
@evhub
@michaeltingley Not currently, but there's no fundamental technical obstacle to it. Feel free to raise an issue for it.
Actually, one other thing you could do is just use something like mypy-ipython, which should work inside of a Coconut kernel, since Coconut's kernel supports magics/extensions (though I haven't tested mypy-ipython myself).
Mihai Eugen Miuta
@miutamihai
Hi everyone! I just started out using coconut and I absolutely love it (especially the lambda function syntax change). Speaking of lambdas, I was wondering whether there's a way of using the addpattern syntax with lambda expressions. That would absolutely seal the deal for me :smile:
Evan Hubinger
@evhub

@miutamihai Statement lambdas certainly offer support for pattern-matching syntax—for example:

xs |> map$(def ({"a": a}) -> a + 1)

And in terms of using addpattern, it's just a function, so you can certainly do something like:

def ignore_zero(x, 0) = float("nan")
safediv = addpattern(ignore_zero)(def (x, y) -> x / y)
Thurston Sexton
@tbsexton
@evhub how would you like #513 to be addressed in practice? IMO we typically see something that looks like coconut-language-server as its own separate repo. Do you want to make a base repo with the dev-ops stuff you prefer, for us to PR to it? I've been researching how to implement an LSP with pylgs: https://github.com/openlawlibrary/pygls
Thurston Sexton
@tbsexton
(unrelated: think I could do a quick PR to add this to your conf.py? the sidebar never scrolls unless I get waaaay down in the docs... just a minor pet peeve ^_^ https://github.com/ryan-roemer/sphinx-bootstrap-theme/issues/136#issuecomment-186860368)
Evan Hubinger
@evhub
@tbsexton Separate repo seems good and if you want to just make it that seems good to me. I don't anticipate being able to contribute a ton, but certainly if there's anything I can do on the Coconut side to make things easier I'd be happy to.
Re doc sidebar scrolling, I just pushed evhub/coconut@2bd81da which bumps the version per the PR you linked; hopefully that fixes the issue.
Thurston Sexton
@tbsexton
oh cool. You may need to add something like 'navbar_fixed_top': "false", to the html settings in sphinx, per the last comment on that issue
Evan Hubinger
@evhub
@tbsexton Ah, thanks—pushed evhub/coconut@78bb495
Thurston Sexton
@tbsexton
Hmm that didn't do what I expected ^_^ now the sidebar is locked to the top of the page (which i guess is obvious in retrospect haha) ... so we can't navigate from within the docs somewhere
Maybe the best "alternative" is the globaltoc_depth:3 option? It that does what I'm assuming, then the sidebar would just have less "stuff" in it.
Apologies, i'm not super familiar with the options in this sphinx theme (more of a mkdocs-material user myself)
Evan Hubinger
@evhub
Just reading the documentation, I don't think globaltoc_depth does what you want—it looks like it conrols the "Site" dropdown, not the navbar.