bintoro / overloading.py

Function overloading for Python 3
MIT License
112 stars 10 forks source link

AttributeError: module 'typing' has no attribute 'TypingMeta' #8

Open Hendiadyoin1 opened 5 years ago

Hendiadyoin1 commented 5 years ago

for some reason my program throws this error rooted in this lib. when i try to simply overload the init of my class. Code:

from overloading import overload
import cmath

class Quaternion:
    def __init__(self, r: int, i: int, j: int, k: int):
        self.r = r
        self.i = i
        self.j = j
        self.k = k

    @overload
    def __init__(self, c: complex):
        self.r = c.real
        self.i = c.imag

print(Quaternion(1, 2, 3, 4).r)
print(Quaternion(1 + 2j).r)

Error:

Traceback (most recent call last): File "C:...\Python\Python37\lib\site-packages\overloading.py", line 63, in overload return register(registry[fname], func) KeyError: 'main.Quaternion.init__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:...\Python\Testing\quaternion.py", line 6, in class Quaternion: File "C:...\Python\Testing\quaternion.py", line 14, in Quaternion def init(self, c: complex): File "C:...\Python\Python37\lib\site-packages\overloading.py", line 65, in overload __registry[fname] = overloaded(func) File "C:...\Python\Python37\lib\site-packages\overloading.py", line 151, in overloaded return register(dispatcher, func) File "C:...\Python\Python37\lib\site-packages\overloading.py", line 199, in register signature = get_signature(fn) File "C:...\Python\Python37\lib\site-packages\overloading.py", line 441, in get_signature types = tuple(normalize_type(type_hints.get(param, AnyType)) for param in parameters) File "C:...\Python\Python37\lib\site-packages\overloading.py", line 441, in types = tuple(normalize_type(type_hints.get(param, AnyType)) for param in parameters) File "C:...\Python\Python37\lib\site-packages\overloading.py", line 468, in normalizetype if not typing or not isinstance(type, typing.TypingMeta) or type_ is AnyType: AttributeError: module 'typing' has no attribute 'TypingMeta'

fpiedrah commented 5 years ago

Same here, python 3.7

Paprikar commented 4 years ago

The downgrade of the typing module helped me (from the python repository) to version 3.5.2.2. You can also forcefully ignore the typing module in the overloading module by assigning typing = None after the 30th line in the file overloading.py, but I think the typing module features will not be available.

tony-is-coding commented 4 years ago

such an unfortunately infomation ! we want use python3; this maybe an solution for overload: https://python3-cookbook.readthedocs.io/zh_CN/latest/c09/p20_implement_multiple_dispatch_with_function_annotations.html

kaimingkuang commented 3 years ago

The downgrade of the typing module helped me (from the python repository) to version 3.5.2.2. You can also forcefully ignore the typing module in the overloading module by assigning typing = None after the 30th line in the file overloading.py, but I think the typing module features will not be available.

Same issue here. Downgrading all the way to 3.5 sounds like a major hassle.

ImahnShekhzadeh commented 1 year ago

I have the same issue. @bintoro If you ask me, this project should be archived, since it's not in active development and does not work for the newest versions of python.

SnayperTihCreator commented 3 weeks ago

я не знаю как это влияет но можно использовать _GenericAlias вместо TypingMeta будет работать