On 08/10/2025 3:38, Vincent Macri wrote:
sage: class B(A): ....: def foo(self): ....: return 42 ....: sage: b = B() sage: b.foo() 42 sage: b.bar() # surprise? 5 sage: b.__getattribute__("bar").__name__ 'foo' sage: b.__getattribute__("foo").__name__ 'foo'That's an interesting test case! But I think using __qualname__ instead of __name__ allows these kinds of situations to be handled. I'm curious if there is anywhere where this happens in Sage, if so that could be a bug. I'm also wondering if this situation could be detected by linters.
You are correct here, and also in your comment that typing.override can help in certain situations. Here, a user-defined class that inherits from a Sage class might be unaware of an alias, so also users will need to somehow detect this.
Maybe your code for the docs that detects aliases, can later use some magic to inspect the mro of those classes. I could not find previous reports of such cases (in Sage or more generally in Python), though they must have happen before, especially in large or complicated class hierarchies.
Loosely related, I just opened #41022. The bug there, as far as I understand, stems from not overriding a method in a derived class (but unrelated to an alias).
Regards, TB -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sage-devel/63e94e0b-7009-4432-a3d0-8277d1b899e0%40gmail.com.
