Addpattern with mypy - name already defined
See original GitHub issueI was going throught the case studies for coconut
tutorial and tried using addpattern
def factorial(0) = 1
addpattern def factorial(n is int if n > 0) =
"""Compute n! where n is an integer >= 0."""
n * factorial(n - 1)
# Test cases:
-1 |> factorial |> print # MatchError
0.5 |> factorial |> print # MatchError
0 |> factorial |> print # 1
3 |> factorial |> print # 6
Now compiling with coconut fact.coco --mypy
yielded
CoconutWarning: missing __init__.coco in package: '...'
Compiling fact.coco ...
Compiled to fact.py .
fact.py:39: error: Name 'factorial' already defined on line 23
Found 1 error in 1 file (checked 1 source file)
Exiting due to MyPy error.
The code runs and all but I want to know if this is expected and desired output from mypy
?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to circumvent 'name already defined error' in mypy?
When I run mypy against this, it will have the following error: Name 'A' already defined (possibly by an import).
Read more >Common issues and solutions - mypy 0.991 documentation
NameError: name "X" is not defined from forward references. TypeError: 'type' object is not subscriptable from types that are not generic at runtime....
Read more >Python Type Hints - Mypy doesn't allow variables to change type
Mypy does not allow variables to change type. I found this a little bit of a shock at first, but after I adapted,...
Read more >Mypy Documentation - Read the Docs
mypy was able to understand that name could not possibly be None in the greeting function ... The type Any is defined in...
Read more >python/mypy - Gitter
On the for loop I want to identify the type of the vars (row and event), but mypy tells me that data_processing.py:144: error:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Related to #520, Coconut could add
# type: ignore[no-redef]
whenaddpattern
is used. For me, ideally, it could be added only whenaddpattern
is used before the function is called, but I guess this is very hard to implement. Maybe include# type: ignore[no-redef]
whenaddpattern
is used right on the same file where function was declared.@EmilRehnberg #510 would not resolve this issue, as even after you give the function a unique name you still need to reassign it if you want it to override the old name. So I think it still makes sense to consider whether Coconut should pass
--allow-redefinition
by default. I’m going to leave this issue open for that reason.