Comments (7)
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.
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.
casting still gives us the same error, actually?
how does one "tell typeshed" to type something with a protocol anyway?
from coconut.
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.
still getting the error; would it matter if it's vector(*pts)
instead of vector(pts)
in the data type?
from coconut.
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.
>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)
- Walruses aren't allowed in places where they should be HOT 1
- Implicit application doesn't work if the function's first token is a string literal HOT 2
- unicode alternative of multiple-argument pipe backward `↤*` does not work HOT 1
- Add walrus operator function implicit partial
- Some Unicode characters are replaced with a newline HOT 1
- fmap support for bytes HOT 1
- Coefficient syntax error message is too specific HOT 3
- When to output colors handled incorrectly HOT 1
- Conda-Forge package is marked x86 only HOT 1
- Assignment functions with compound statement HOT 1
- Shorthand for match assignment functions HOT 14
- Empty `zip` objects error on `__len__` HOT 2
- Destructuring first and last item HOT 1
- Add `CoconutWarning` for all Coconut runtime warnings
- `--strict` should disallow implicit string concatenation
- Allow custom numpy integration
- Some f-strings don't parse correctly HOT 1
- Wrong f-string parsing and compile warning HOT 1
- Improve implicit partial application HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coconut.