NameError: name '__beartype_random_int' is not defined
See original GitHub issueSince the glorious update to 0.3, I encountered a slight issue with using lists of pathlib Path objects. I’m not sure whether it is specific to pathlib Paths in particular, but this was what I whittled it down to as a minimal script that produces the issue:
from typing import List
from pathlib import Path
from beartype import beartype
class UserDefinedType:
def __repr__(self):
return "I am a user-defined type"
@beartype
def working_example(x: List[Path]):
print(f"working_example >>> I will get to see {x}")
@beartype
def working_combination(x: List[int], y: int):
print(f"working_combination >>> I get to see {x} and {y}")
@beartype
def working_combination_udt(x: List[UserDefinedType], y: int):
print(f"working_combination with UDT >>> I get to see {x} and {y}")
@beartype
def not_working_combination(x: List[Path], y: int):
print(f"not_working_combination: Sadly, I will never see {x} or {y}")
if __name__ == "__main__":
path_list = [Path("/a/b")]
int_list = [0]
udt_list = [UserDefinedType()]
# works OK
working_example(x=path_list)
working_combination(x=int_list, y=0)
working_combination_udt(x=udt_list, y=0)
# breaks
not_working_combination(x=path_list, y=0)
This produces the output:
working_example >>> I will get to see [PosixPath('/a/b')]
working_combination >>> I get to see [0] and 0
working_combination with UDT >>> I get to see [I am a user-defined type] and 0
Traceback (most recent call last):
File "debug.py", line 43, in <module>
not_working_combination(x=path_list, y=0)
File "<string>", line 25, in __beartyped_not_working_combination
NameError: name '__beartype_random_int' is not defined
It’s easy for me to work around for now by reverting to using list
as an annotation (rather than List[Path]
), but just thought I’d flag it as a potential issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
NameError: name 'List' is not defined - python - Stack Overflow
If I try importing List first I get an error No module named 'List' . I'm using Python 3.7.3 from Anaconda. python ·...
Read more >Python nameerror name is not defined Solution - Career Karma
A NameError is raised when you try to use a variable or a function name that is not valid. In Python, code runs...
Read more >NameError: name 'os' is not defined - LearnDjango.com
Starting with Django 3.1, the startproject command generates a settings.py file that imports pathlib rather than os on the top line. The quick ......
Read more >NameError: Name plot_cases_simple is Not Defined
In Python, the NameError occurs when you try to use a variable, function, or module that doesn't exist or wasn't used in a...
Read more >NameError: name 'os' is not defined - Forums - IBM Support
NameError : name 'os' is not defined. I used. for root, dirs, files in os.walk(pfad, topdown=True): .... can someone help me with this?...
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
Ka-blammo!
beartype 0.3.1
is up on all the usual suspects. This turned out to be a surprisingly involved issue. On the bright side, we’ve resolved a critical memoization defect and written unit tests exhaustively exercising this defect across all possible edge cases. On the dark side, this should never have happened.But that’s 2020 for you. Urgh!
Ah-ha! It’s an obscure function memoization issue. You really don’t want to know. This is why friends don’t let friends memoize drunk, people.
I’ll have this patched up and
beartype 0.3.1
pushed out the Canadian cabin door in a jiffy.