You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ pip install nuitka overrides
$ python bug.py
B
$ python -m nuitka bug.py
...
Nuitka:INFO: Successfully created 'bug.bin'.
$ ./bug.bin
Traceback (most recent call last):
File "/mnt/c/code/bug.py", line 8, in<module>
class B(A):
File "/mnt/c/code/bug.py", line 9, in B
@override
File "/home/bers/.local/lib/python3.10/site-packages/overrides/overrides.py", line 143, in override
return _overrides(method, check_signature, check_at_runtime)
File "/home/bers/.local/lib/python3.10/site-packages/overrides/overrides.py", line 172, in _overrides
raise TypeError(f"{method.__qualname__}: No super class method found")
TypeError: B.hello: No super class method found
It seems the overrides packages parses byte code, which is really hard when there is no such thing. I find it confusing why it would do that. At least in your example, that seems unnecessary. It appears it would allow to see assignments that will be done later.
Now it will be an interesting puzzle to solve this. Effectively, _get_base_class_names(frame) would have to be executed at compile time, and then at run time, where to code object, say qualname would have to be a key, into a dictionary with the identifiers.
However, outside of Nuitka commercial I do not see myself doing this for a while. With somebody willing to pay my time there, no problem, but right now there is more important stuff to do otherwise.
This looks like a good solution, too - I'll keep that in mind.
In the meantime, I think I found a good fix to @override myself (compare mkorpela/overrides#112), so maybe it's not even required to add overrides to Nuitkas list of bad-behavers. I'll see if my proposed change can be considered for override.
I will try that later, just replaces the whole function with that lambda. We do similar for other software I took this from 'tensorflow.python.ops.distributions.distribution' configuration.
I'm not at all sure should I merge the PR to overrides mkorpela/overrides#112 it basically silently just fails the whole operation.
It seems the overrides packages parses byte code, which is really hard when there is no such thing. I find it confusing why it would do that.
Because it checks override during class loading and that is the place where the super class is found from.
How would that (checking method override) work in case of a pre-compiled language?
I'm not at all sure should I merge the PR to overrides mkorpela/overrides#112 it basically silently just fails the whole operation.
I agree - would it help if we made the check more specific? I noticed that dis.get_instructions(frame.f_code) returns an empty iterator, but I assume one may go a bit further still to find a specific indication that there is no byte code.
How would that (checking method override) would work in case of a pre-compiled language?
Interesting, thank you! Maybe Nuitka can (has to?) consider that one as well, and in effect consider both overrides.override and the new typing.override in one.
For the record, it will be in Python 3.12 via python/cpython#101564. Until then it is also available via python/typing_extensions#78. Since that "official" decorator is defined to not have any runtime effects, I would guess Nuitka does not have to care about either of those.
Whether Nuitka will need to support overrides certainly depends on what @mkorpela's plans are. @mkorpela, will you keep maintaining it to offer runtime checks, or will you deprecate? To be honest, I will probably switch from overrides to typing(_extensions) once mypy supports it (python/mypy#14072), because it means one less dependency and I am happy with mypy reporting override errors.
For whatever feature is added to Python, there is always a backport available, that Nuitka gets to support. I doubt it will be different in this case, otherwise the feature will be unavailable for use in practically all libraries.
For whatever feature is added to Python, there is always a backport available, that Nuitka gets to support.
I understand that.
I doubt it will be different in this case, otherwise the feature will be unavailable for use in practically all libraries.
Well, what is different in this case is that, as I wrote, @override is defined to not have runtime effects, so Nuitka would not need to support any. I just checked, and this code runs fine after compilation with Nuitka:
That's good. For that overrides package there is a fix on factory branch now. The typing_extensions are also a backport, are they, or just another implementation of the same thing, that will be in typing in the future?
Activity
kayhayen commentedon Feb 10, 2023
It seems the
overridespackages parses byte code, which is really hard when there is no such thing. I find it confusing why it would do that. At least in your example, that seems unnecessary. It appears it would allow to see assignments that will be done later.Now it will be an interesting puzzle to solve this. Effectively,
_get_base_class_names(frame)would have to be executed at compile time, and then at run time, where to code object, say qualname would have to be a key, into a dictionary with the identifiers.However, outside of Nuitka commercial I do not see myself doing this for a while. With somebody willing to pay my time there, no problem, but right now there is more important stuff to do otherwise.
bersbersbers commentedon Feb 10, 2023
No problem at all! I can easily fallback by such a construct here:
Is there an ideal way to check that my code has been/is being compiled by Nuitka?
PyInstallerdefinessys.frozen, for instance: https://pyinstaller.org/en/stable/runtime-information.htmlkayhayen commentedon Feb 10, 2023
This looks then more like something the anti-bloat engine could do instead. Just replace
@overridewith empty string. Check out this: https://nuitka.net/posts/nuitka-package-config-kickoff.htmlIf that is functionality equivalent (I think doc strings will not be copied), then we can get away with that and call it a day. Will you create a PR?
bersbersbers commentedon Feb 10, 2023
This looks like a good solution, too - I'll keep that in mind.
In the meantime, I think I found a good fix to
@overridemyself (compare mkorpela/overrides#112), so maybe it's not even required to addoverridestoNuitkas list of bad-behavers. I'll see if my proposed change can be considered foroverride.kayhayen commentedon Feb 11, 2023
Yes, we can do that, or even replace the whole function. You can experiment with this:
I will try that later, just replaces the whole function with that lambda. We do similar for other software I took this from
'tensorflow.python.ops.distributions.distribution'configuration.kayhayen commentedon Feb 11, 2023
I feel that's probably already the solution and of course could be in a next hotfix once confirmed.
bersbersbers commentedon Feb 11, 2023
Alright, will check tomorrow. Not sure yet if we need to change
overrides.override,overrides.overrides, or both. Compare mkorpela/overrides@5d67cab4 remaining items
mkorpela commentedon Feb 12, 2023
I'm not at all sure should I merge the PR to overrides mkorpela/overrides#112 it basically silently just fails the whole operation.
Because it checks override during class loading and that is the place where the super class is found from.
How would that (checking method override) work in case of a pre-compiled language?
I know that Python 3.12 will have a override decorator in types https://peps.python.org/pep-0698/
bersbersbers commentedon Feb 12, 2023
I agree - would it help if we made the check more specific? I noticed that
dis.get_instructions(frame.f_code)returns an empty iterator, but I assume one may go a bit further still to find a specific indication that there is no byte code.No idea, unfortunately.
Interesting, thank you! Maybe Nuitka can (has to?) consider that one as well, and in effect consider both
overrides.overrideand the newtyping.overridein one.bersbersbers commentedon Feb 12, 2023
For the record, it will be in Python 3.12 via python/cpython#101564. Until then it is also available via python/typing_extensions#78. Since that "official" decorator is defined to not have any runtime effects, I would guess Nuitka does not have to care about either of those.
Whether
Nuitkawill need to supportoverridescertainly depends on what @mkorpela's plans are. @mkorpela, will you keep maintaining it to offer runtime checks, or will you deprecate? To be honest, I will probably switch fromoverridestotyping(_extensions)oncemypysupports it (python/mypy#14072), because it means one less dependency and I am happy withmypyreportingoverrideerrors.kayhayen commentedon Feb 12, 2023
For whatever feature is added to Python, there is always a backport available, that Nuitka gets to support. I doubt it will be different in this case, otherwise the feature will be unavailable for use in practically all libraries.
bersbersbers commentedon Feb 12, 2023
I understand that.
Well, what is different in this case is that, as I wrote,
@overrideis defined to not have runtime effects, so Nuitka would not need to support any. I just checked, and this code runs fine after compilation with Nuitka:kayhayen commentedon Feb 12, 2023
That's good. For that
overridespackage there is a fix on factory branch now. Thetyping_extensionsare also a backport, are they, or just another implementation of the same thing, that will be intypingin the future?bersbersbers commentedon Feb 12, 2023
Great!
Not sure I understand the difference to be honest. I'd say both, I guess. Check these two links for current implementations:
https://github.com/python/cpython/pull/101564/files#diff-ddb987fca5f5df0c9a2f5521ed687919d70bb3d64eaeb8021f98833a2a716887R3458-R3491
https://github.com/python/typing_extensions/blob/e81cb8289874d6a6715675d77df88db033824e0d/src/typing_extensions.py#L2093-L2131
kayhayen commentedon Feb 13, 2023
I had to make a hotfix the other day, and the change is actually part of 1.4.6 because it's only config.