Giter Site home page Giter Site logo

Comments (7)

deli73 avatar deli73 commented on September 25, 2024

on second thought, the isinstance check might be redundant anyways with type checking.
however, similar issues here:

def __abs__(self) -> float =
        """Return the magnitude of the vector."""
        self.pts |> map$(.**2) |> sum |> (.**0.5)

Mypy can't check the type correctly, so we just get this.

hello.py: note: In member "__abs__" of class "vector":
hello.py:132:9: error: Returning Any from function declared to return "float"  [no-any-return]
            return _coconut_tail_call((_coconut.operator.pow), (sum)((map)(_coconut_complex_partial(_coconut.opera...
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...
Found 1 error in 1 file (checked 1 source file)
Coconut exiting with error: MyPy error

from coconut.

evhub avatar evhub commented on September 25, 2024

Hmm... I don't think there's much that I can do here. The core problem as you noted is that the type of builtins.pow is (typing.Any, typing.Any) -> typing.Any, which is really a typeshed issue. An easy fix is just to do

import typing
self.pts |> map$(.**2) |> sum |> (.**0.5) |> typing.cast$(float)

but the correct fix here is to tell typeshed to type builtins.pow with a typing.Protocol instead of just with typing.Any.

from coconut.

deli73 avatar deli73 commented on September 25, 2024

casting still gives us the same error, actually?
how does one "tell typeshed" to type something with a protocol anyway?

from coconut.

evhub avatar evhub commented on September 25, 2024

casting still gives us the same error, actually?

Strange; I can't seem to reproduce that. Maybe try moving to coconut-develop (pip uninstall coconut && pip install -U coconut-develop)? The code I'm running here is:

from typing import cast
data vector(pts):
    def __abs__(self) -> float =
        """Return the magnitude of the vector."""
        self.pts |> map$(.**2) |> sum |> (.**0.5) |> cast$(float)

how does one "tell typeshed" to type something with a protocol anyway?

Just raise an issue telling them to do it or open a pull request making the change yourself.

from coconut.

deli73 avatar deli73 commented on September 25, 2024

still getting the error; would it matter if it's vector(*pts) instead of vector(pts) in the data type?

from coconut.

evhub avatar evhub commented on September 25, 2024

It works for me with data vector(*pts) too. How are you testing this? What happens if you try pasting it into the terminal with coconut --mypy?

from coconut.

deli73 avatar deli73 commented on September 25, 2024
>coconut --mypy
Coconut Interpreter v3.0.4-post_dev22 (Python 3.11):
(enter 'exit()' or press Ctrl-D to end)
>>> from typing import cast
data vector(pts):
    def __abs__(self) -> float =
        """Return the magnitude of the vector."""
        self.pts |> map$(.**2) |> sum |> (.**0.5) |> cast$(float)
<string>: note: In member "__add__" of class "vector":
<string>:63:5: error: Function is missing a type annotation  [no-untyped-def]
<string>: note: In member "__mul__" of class "vector":
<string>:64:5: error: Function is missing a type annotation  [no-untyped-def]
<string>: note: In member "__rmul__" of class "vector":
<string>:65:5: error: Function is missing a type annotation  [no-untyped-def]
<string>: note: In member "__eq__" of class "vector":
<string>:67:5: error: Function is missing a type annotation  [no-untyped-def]
<string>: note: In member "__hash__" of class "vector":
<string>:69:5: error: Function is missing a return type annotation  [no-untyped-def]
<string>: note: In member "__abs__" of class "vector":
<string>:75:9: error: Returning Any from function declared to return "float"  [no-any-return]

still same error, as far as we can tell... are we using the wrong version of Python for this?

from coconut.

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.