question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Addpattern with mypy - name already defined

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
FelipeSharkaocommented, Sep 16, 2021

Related to #520, Coconut could add # type: ignore[no-redef] when addpattern is used. For me, ideally, it could be added only when addpattern is used before the function is called, but I guess this is very hard to implement. Maybe include # type: ignore[no-redef] when addpattern is used right on the same file where function was declared.

1reaction
evhubcommented, Dec 12, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found